0

我想将DateTimePicker.Text 绑定到DateTimePicker.SelectedDate,以便始终使用.SelectedDate.

我成功地做相反的事情(绑定DateTimePicker.SelectedDateDateTimePicker.Text),但没有DateTimePicker.Text到 D ateTimePicker.SelectedDate

这是我的 XAML:

<DatePicker x:Name="DateTimePicker_Date" SelectedDate = "{Binding this.dDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, TargetNullValue=''}"  />

有谁知道我的错误在哪里?

非常感谢 :)

4

1 回答 1

0

用这个

   <DatePicker Name="MyDatePicker" Text="{Binding Path=ActualDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, TargetNullValue=''}" />

实际日期在哪里

    private Datetime mActualDate;

    public DateTime ActualDate
    {
        get
        {
            return mActualDate;
        }
        set
        {
            if (value != null)
            {

                        mActualDate= value;
                        NotifyPropertyChanged("ActualDate");
            }
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    // NotifyPropertyChanged will raise the PropertyChanged event, 
    // passing the source property that is being updated.
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this,
                new PropertyChangedEventArgs(propertyName));
        }
    }
于 2013-05-07T08:37:05.540 回答