WPF DatePicker UpdateSourceTrigger PropertyChanged 不起作用
我正在使用 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"));
}
}
SubmitCommand.RaiseCanExecuteChanged()
应该在我在 DateTimePicker 上输入任何字符后启用该按钮,但它没有发生。
I am using MVVM and want to enable a button on text change of datepicker control..
XAML Code:
Binding on DatePicker
SelectedDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
Binding on Button:
<Button Margin="10" Command="{Binding SubmitCommand}"
View Model Code:
I am using a DelegateCommand for button click
View Model Delegate Initialization
SubmitCommand = new DelegateCommand(OnSubmitRequested, AllowSubmit, Controller);
The AllowSubmit implementation
private bool AllowSubmit()
{
return InactiveDate != null;
}
InactiveDate Property implementation
public DateTime? InactiveDate
{
get
{
return _inactiveDate;
}
set
{
_inactiveDate = value;
SubmitCommand.RaiseCanExecuteChanged();
PropertyChanged(this, new PropertyChangedEventArgs("InactiveDate"));
}
}
SubmitCommand.RaiseCanExecuteChanged()
should enable the button once I enter any character on DateTimePicker but it is not happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所选日期属性无法正常工作。我现在可能有点晚了,但是您可以使用 RadDatePicker 的 CurrentDateTimeText 属性
Selected Date property does not work properly. I might be a bit late now, but you can use CurrentDateTimeText property of RadDatePicker