单独的事件检查和WPF CheckBox的选中状态:为什么呢? [英] Separate events for checked and unchecked state of WPF CheckBox: Why?

查看:1504
本文介绍了单独的事件检查和WPF CheckBox的选中状态:为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 有没有像一个单一的事件更改,我可以用它来处理这两种事件一起呢?

  2. 为什么他们分开这样吗?
    是不是因为有一个单一的事件,双方会要求您引用的名字,你就需要指定在XAML的控制,而这将增加混乱?

解决方案
  1. 不直接。但是,您可以使用相同的事件处理程序为,并查询发件人参数器isChecked 属性(铸造后为复选框切换按钮当然)。
  2. 都需要特定的WPF技术的两个事件,故事情节一样, EventTriggers 和类似。 EventTriggers 能状态无法区分,只能通过事件,因此需要两个不同的事件。

在一般的笔记:我不会用这些事件在所有 - 我会在器isChecked 属性绑定到你的视图模型一个适当的财产,让您的code-背后最低(理想情况下没有自定义code在所有)。

  1. Is there a single event like Changed that I can use to handle both events together?

  2. 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?

解决方案

  1. Not directly. However, you can use the same event handler for both, and query the IsChecked property of the sender parameter (after casting it to CheckBox or ToggleButton of course).
  2. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆