WPF复选框:检查更改处理 [英] WPF Check box: Check changed handling
问题描述
在WPF数据绑定,我可以在物业器isChecked绑定到一些数据,例如用户设置,但我需要处理CheckChanged事件,我知道我能单独处理的的检查的 未选中的事件,但有什么办法,当该值更改为得到通知
In WPF data binding, I can bind the IsChecked property to some data, e.g. user setting, but I need to handle "CheckChanged" event, I know I can seperately handle Checked, Unchecked event, but is there any way to get notified when this value is changed?
<CheckBox Content="Case Sensitive" IsChecked="{Binding bSearchCaseSensitive,
Source={x:Static Properties:Settings.Default}}" />
请注意:如果选中或取消选中我不在乎。我只是想,当它改变时得到通知。
Note: I don't care if it is checked or unchecked. I just want to be notified when it is changed.
推荐答案
这是你的可以的处理检查,选中的事件分开并不意味着你的必须的。如果您不想跟着你可以简单地将相同的处理连接到这两个事件MVVM模式,你有你的改变信号:
That you can handle the checked and unchecked events seperately doesn't mean you have to. If you don't want to follow the MVVM pattern you can simply attach the same handler to both events and you have your change signal:
<CheckBox Checked="CheckBoxChanged" Unchecked="CheckBoxChanged"/>
和代码隐藏;
private void CheckBoxChanged(object sender, RoutedEventArgs e)
{
MessageBox.Show("Eureka, it changed!");
}
请注意,WPF大力鼓励利用INotifyPropertyChanged的和/或DependencyProperties的MVVM模式一个原因。这是一些作品,不是我想尽量鼓励良好的编程习惯。
Please note that WPF strongly encourages the MVVM pattern utilizing INotifyPropertyChanged and/or DependencyProperties for a reason. This is something that works, not something I would like to encourage as good programming habit.
这篇关于WPF复选框:检查更改处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!