【问题标题】:CheckBox CheckChanged eventCheckBox CheckedChanged 事件
【发布时间】:2018-06-02 21:34:36
【问题描述】:

在Checkbox.IsChecked = true 之后,会触发 Checked 事件。 在Checkbox.IsChecked = false 之后,会触发 UnChecked 事件。 但是IsChecked = null 之后会触发什么事件?

【问题讨论】:

  • 你将如何触发该事件?
  • Checkbox.IsChecked = null 之后我需要一个事件。我不明白为什么没有像 WinForms 中的 CheckedChanged 事件那样的 IsCheckedChanged 事件?

标签: c# .net wpf events checkbox


【解决方案1】:

当IsChecked 设置为空时,复选框将显示不确定状态。查看此link 了解更多详情。您可以像这样编写不确定状态的代码:

<CheckBox Checked="CheckBox_Checked"
 Unchecked="CheckBox_Unchecked"
 Indeterminate="CheckBox_Indeterminate"
 IsThreeState="True"/>

在后面的代码中:

private void CheckBox_Indeterminate(object sender, RoutedEventArgs e)
{
  //write some code in Indeterminate states
}

Indeterminate 是当CheckBox 的状态切换到不确定状态时发生的事件。你可以查看这个关于Indeterminate Event的链接。

【讨论】:

  • 谢谢,indeterminate 是我正在寻找的事件。
【解决方案2】:

该事件称为Indeterminate。当您将 IsChecked 属性设置为 null 或什么都没有时,它会触发。 See this page on MSDN

【讨论】:

    猜你喜欢
    • 2021-04-21
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 2020-05-28
    相关资源
    最近更新 更多