English 中文(简体)
IsSynchronizedWithCurrentItem (or equivalent) for a DatePicker?
原标题:

I currently have a combobox with bound to an ObservableCollection

    <ComboBox ItemsSource="{Binding Past}" DisplayMemberPath="Date" IsSynchronizedWithCurrentItem="True"/>

Using, IsSynchronizedWithCurrentItem it "synchronizes" with a set of labels that show the data below in a set of labels like:

    <Label DataContext="{Binding SelectedDate}" Content="{Binding Minimum}" />

As it is a lot easier to select a date using a DatePicker (like the WPF Toolkit one, http://wpf.codeplex.com/) rather than a combobox with over 300 dates in it, is there someway to set something like IsSynchronizedWithCurrentItem so that the DatePicker can control the current date ?

Thank you

最佳回答

I solved this by creating a CurrentDate Property in my View Model:

    public DateTime CurrentDate
    {
        get { return (this.collectionView.CurrentItem as PastItem).Date; }
        set 
        { 
            this.collectionView.MoveCurrentTo(Past.Where(PastItem => PastItem.Date == Convert.ToDateTime(value)).FirstOrDefault()); 
        }
    }

and then creating two property s for the first & the last dates:

    public DateTime FirstDate
    {
        get { return this.Past.FirstOrDefault().Date; }
    }
    public DateTime LastDate
    {
        get { return this.Past.LastOrDefault().Date; }
    }

and then binding to these properties using the DatePicker:

    <wpf:DatePicker SelectedDate="{Binding CurrentDate}" DisplayDateStart="{Binding FirstDate, Mode=OneWay}" DisplayDateEnd="{Binding LastDate, Mode=OneWay}" />

This meant that the DatePicker would be limited to the first & the last dates, and one can choose a date, linked to the details.

问题回答

暂无回答




相关问题
DatePicker minDate relative 1 month from start date

How do I set the #endDatePicker 1 month to the future of the selected date from #startDatePicker? I am not figuring this one out but I am sure it is easier than I am making it. Here is what I am ...

datepicker in JQuery UI Dialog shows calendar on dialog open

I have a JQuery modal dialog with 2 JQuery UI datepicker inputs. My problem is that when the dialog opens the calendar is already open on the page. I am not sure if this is because it is getting focus ...

jQuery datepicker to prevent past date

How do I disable past dates on jQuery datepicker? I looked for options but don t seem to find anything that indicates the ability to disable past dates. UPDATE: Thanks yall for the quick response. I ...

Silverlight DatePicker in DataGrid allow NULL dates

I have a DataGrid that has as one of its columns a DatePicker (for the editing template). Is there a way to keep this but still allow a user to enter in a NULL date?

How to reset a field when changing a date ui.datepicker.js

I m using ui.datepicker.js I have a form and when the date is changed I want that another field reset the status (this field is a dropdown select box). The case is the following: The user enter the ...

Not finding defaultDate in jQuery UI datepicker

I have a form text field that pulls a date from a database (in the format yyyy-mm-dd). <input class="" type="text" name="closingDate" id="closingDate" value="<?php echo $closingdate;?>" />...

热门标签