【问题标题】:WPF DatePicker UpdateSourceTrigger PropertyChanged not workingWPF DatePicker UpdateSourceTrigger PropertyChanged 不起作用
【发布时间】:2010-12-30 04:50:00
【问题描述】:

我正在使用 MVVM 并希望在日期选择器控件的文本更改上启用一个按钮..

XAML 代码: 在 DatePicker 上绑定

SelectedDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

按钮绑定:

<Button Margin="10" Command="{Binding SubmitCommand}"

查看型号代码: 我正在使用 DelegateCommand 进行按钮单击

查看模型委托初始化

SubmitCommand = new DelegateCommand(OnSubmitRequested, AllowSubmit, Controller);

AllowSubmit 实现

private bool AllowSubmit()
{
    return InactiveDate != null;
}

InactiveDate 属性实现

    public DateTime? InactiveDate
    {
        get
        {
            return _inactiveDate;
        }

        set
        {
            _inactiveDate = value;
            SubmitCommand.RaiseCanExecuteChanged();
            PropertyChanged(this, new PropertyChangedEventArgs("InactiveDate"));
        }
    }

一旦我在 DateTimePicker 上输入任何字符,SubmitCommand.RaiseCanExecuteChanged() 应该启用按钮,但它没有发生。

【问题讨论】:

    标签: wpf updatesourcetrigger


    【解决方案1】:

    Selected Date 属性无法正常工作。我现在可能有点晚了,但是您可以使用 RadDatePicker 的 CurrentDateTimeText 属性

    【讨论】:

      猜你喜欢
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 2010-12-29
      相关资源
      最近更新 更多