我正在使用 MVVM 并希望在 datepicker 控件的文本更改上启用一个按钮..
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"));
}
}
SubmitCommand.RaiseCanExecuteChanged()
一旦我在 DateTimePicker 上输入任何字符,应该启用该按钮,但它没有发生。