单独的事件检查和WPF CheckBox的选中状态:为什么呢? [英] Separate events for checked and unchecked state of WPF CheckBox: Why?
问题描述
-
有没有像一个单一的事件
更改
,我可以用它来处理这两种事件一起呢? -
为什么他们分开这样吗?
是不是因为有一个单一的事件,双方会要求您引用的名字,你就需要指定在XAML的控制,而这将增加混乱?
- 不直接。但是,您可以使用相同的事件处理程序为,并查询
发件人
参数器isChecked
属性(铸造后为复选框
或切换按钮
当然)。 - 都需要特定的WPF技术的两个事件,故事情节一样,
EventTriggers
和类似。EventTriggers
能状态无法区分,只能通过事件,因此需要两个不同的事件。
在一般的笔记:我不会用这些事件在所有 - 我会在器isChecked
属性绑定到你的视图模型一个适当的财产
,让您的code-背后最低(理想情况下没有自定义code在所有)。
Is there a single event like
Changed
that I can use to handle both events together?Why are they separated like this?
Is it because having a single event for both would requires you to reference the control by name, which you would need to specify in the XAML, and this would increase the clutter?
- Not directly. However, you can use the same event handler for both, and query the
IsChecked
property of thesender
parameter (after casting it toCheckBox
orToggleButton
of course). - the two events are required for wpf specific technology, like storyboard,
EventTriggers
and similar.EventTriggers
can't distinguish between state, only by event, so two different events are needed.
On a general note: I wouldn't use the events at all - I would bind the IsChecked
property to an appropiate property on your ViewModel
, keeping your code-behind to a minimum (Ideally no custom code at all).
这篇关于单独的事件检查和WPF CheckBox的选中状态:为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!