【发布时间】: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() 应该启用按钮,但它没有发生。
【问题讨论】: