【问题标题】:Make datatemplate checkbox threestates使数据模板复选框三态
【发布时间】:2011-12-12 19:34:03
【问题描述】:

我想让我的数据模板中的复选框具有三态我实现了一个函数来将列表视图列的数据模板设置为复选框:但我希望它允许三态

public DataTemplate SampleTemplate()
{
    DataTemplate dt = new System.Windows.DataTemplate();
    dt.DataType = typeof(bool);
    FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
    Binding bd = new Binding("EnabledThreading");
    fef.SetBinding(CheckBox.IsCheckedProperty, bd);
    dt.VisualTree = fef;
    return dt;
} 

【问题讨论】:

  • 您是否尝试将IsThreeState 的值设置为true?

标签: c# wpf checkbox datatemplate


【解决方案1】:

设置相应的属性,类似于:

fef.SetValue(CheckBox.IsThreeStateProperty, true);

(如果您没有注意到,FrameworkElementFactory 会被弃用)

【讨论】:

  • 我可以添加选中和未选中的事件处理程序吗?
  • 是的,有一种方法:AddHandler
【解决方案2】:

CheckBox 有一个 IsChecked 属性,它是一个可为空的布尔值,这意味着它可以具有三个可能的值 - true、false 和 null。将其设置为每个实例的适当值。

您还需要将 CheckBox 的 IsThreeState 属性设置为 true。

【讨论】:

    猜你喜欢
    • 2019-01-14
    • 2016-10-26
    • 2011-03-07
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 2010-12-16
    • 1970-01-01
    相关资源
    最近更新 更多