【问题标题】:show values of mutiple properties in tool tip wpf XamDataGrid在工具提示 wpf XamDataGrid 中显示多个属性的值
【发布时间】:2015-07-26 17:17:20
【问题描述】:

我有 xamdatgrid 我动态添加列。我正在使用以下代码将ToolTip 添加到列中。

Binding toolTipBinding = new Binding();
toolTipBinding.Path = new PropertyPath("DataItem.Property1");

Setter toolTipSetter = new Setter();
toolTipSetter.Property = ToolTipProperty;
toolTipSetter.Value = toolTipBinding;
cellValuePresenterStyle.Setters.Add(toolTipSetter);

使用它,我能够将Property1 的值显示为ToolTip。我班上有另一个Property (property2)。我想在ToolTip 中显示Properties 的值。我怎样才能做到这一点

【问题讨论】:

    标签: c# wpf xamdatagrid


    【解决方案1】:

    我不明白你为什么不在 XAML 代码中这样做。但是,如果您确实想通过使用后面的代码来实现这一点。然后执行以下步骤

    1. 使用 MultiBinding 类来做 tooltip 的绑定。

    2. 为两个属性(Property1 和 Property2)创建两个绑定,然后使用 Add 方法将它们添加到您在步骤 1 中创建的多重绑定中。

    3. 创建一个转换器 (IMultiValueConverter) 来编写连接 property1 和 property2 的逻辑。

    4. 按照您已经完成的方式在 setter 值中分配绑定。

    Binding b1=new Binding();  
    

    b1.Path = new PropertyPath("DataItem.Property1");

    Binding b2=new Binding();

    b2.Path = new PropertyPath("DataItem.Property2");

    var toolTipBinding = new MultiBinding();

    toolTipBinding.Bindings.Add(b1);
    toolTipBinding.Bindings.Add(b2);

    toolTipBinding.Converter = new ///your converter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2011-03-10
      相关资源
      最近更新 更多