Search code examples
.netwpfwpfdatagrid

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


Is there a way to dynamically turn on/off tooltips for a WPF DataGrid in the C# code behind?

Thanks.


Solution

  • You could add/remove the Style programmatically:

    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);
        }
    }