【问题标题】:How do I dynamically turn on/off tooltips for a WPF DataGrid in the code behind?如何在后面的代码中动态打开/关闭 WPF DataGrid 的工具提示?
【发布时间】:2017-04-12 13:56:26
【问题描述】:

有没有办法在后面的 C# 代码中为 WPF DataGrid 动态打开/关闭工具提示?

谢谢。

【问题讨论】:

  • 在哪里以及如何设置工具提示?
  • 我在 DataGrid 资源 XAML 中设置:
  • 那么你想什么时候禁用工具提示呢?在什么情况下?有关如何启用和禁用工具提示的示例,请参阅我的答案。

标签: .net wpf wpfdatagrid


【解决方案1】:

您可以通过编程方式添加/删除Style:

Style style;
private void Button_AddOrRemove_Click(object sender, RoutedEventArgs e)
{
    if (dataGrid1.Resources.Count > 0)
    {
        style = dataGrid1.Resources[typeof(DataGridCell)] as Style;
        dataGrid1.Resources.Clear();
    }
    else if (style != null)
    {
        dataGrid1.Resources.Add(typeof(DataGridCell), style);
    }
}

【讨论】:

  • 完美,感谢您的回复。
猜你喜欢
  • 1970-01-01
  • 2012-04-13
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
相关资源
最近更新 更多