作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序中有一个使用 TriState 模式的 CheckBox。这种模式的正常行为似乎是在 null、false、true 之间循环。
我想改变这种行为,让它在空、真、假之间循环。
做到这一点的最佳方法是什么?
我试过添加一个类似于这样的点击处理程序:
void cb_Click(object sender, RoutedEventArgs e)
{
if (((CheckBox)e.Source).IsChecked.HasValue == false)
{
((CheckBox)e.Source).IsChecked = true;
return;
}
if (((CheckBox)e.Source).IsChecked == true)
{
((CheckBox)e.Source).IsChecked = false;
return;
}
if (((CheckBox)e.Source).IsChecked == false)
{
((CheckBox)e.Source).IsChecked = null;
return;
}
}
最佳答案
我猜事件处理程序和默认行为只是取消了彼此的效果,所以复选框似乎被禁用了......
实际上,我最近不得不做同样的事情。我不得不继承CheckBox
并覆盖 OnToggle
:
public class MyCheckBox : CheckBox
{
public bool InvertCheckStateOrder
{
get { return (bool)GetValue(InvertCheckStateOrderProperty); }
set { SetValue(InvertCheckStateOrderProperty, value); }
}
// Using a DependencyProperty as the backing store for InvertCheckStateOrder. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InvertCheckStateOrderProperty =
DependencyProperty.Register("InvertCheckStateOrder", typeof(bool), typeof(MyCheckBox), new UIPropertyMetadata(false));
protected override void OnToggle()
{
if (this.InvertCheckStateOrder)
{
if (this.IsChecked == true)
{
this.IsChecked = false;
}
else if (this.IsChecked == false)
{
this.IsChecked = this.IsThreeState ? null : (bool?)true;
}
else
{
this.IsChecked = true;
}
}
else
{
base.OnToggle();
}
}
}
关于wpf - TriState 复选框 - 如何更改状态的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1343866/
我的应用程序中有一个使用 TriState 模式的 CheckBox。这种模式的正常行为似乎是在 null、false、true 之间循环。 我想改变这种行为,让它在空、真、假之间循环。 做到这一点的
我需要一个可检查的QAction,它除了选中和未选中的模式外还具有部分检查的选项。这基本上已经是 QCheckBox 提供的,但不幸的是,QAction 没有提供。 作为第一次尝试,我通过实现自定义
我正在寻找一种方法来创建一个复选框,该复选框的状态为 undefined 以及状态为打开和关闭。这样的第三种状态在 Mac 上是否常见,如果不是,您如何在可以理解的情况下解决它? 最佳答案 是的,Ma
我是一名优秀的程序员,十分优秀!