如何在后台代码中为 WPF DataGrid 动态打开 on/off 工具提示?

How do I dynamically turn on/off tooltips for a WPF DataGrid in the code behind?

有没有办法在后面的 C# 代码中为 WPF DataGrid 动态转换 on/off 工具提示?

谢谢。

您可以通过编程方式add/remove 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);
    }
}