Skip to content

Repository files navigation

How to show tooltip on the disabled cell in WPF TreeGrid (SfTreeGrid)?

About the sample

This example illustrates how to show tooltip on the disabled cell in WPF TreeGrid (SfTreeGrid)?

WPF TreeGrid (SfTreeGrid) allows you to show the ToolTip through the OnMouseEnter event. But the tooltip will not be displayed for disabled cells in TreeGrid. You can show tooltip for the disabled TreeGridCell and TreeGridExpanderCell in TreeGrid by writing style and enabling ToolTipService.ShowOnDisabled.

<Window.Resources>
    <local:ToolTipConverter x:Key="converter" />

    <Style x:Key="toolTipTreeGridExpanderCell" TargetType="syncfusion:TreeGridExpanderCell">
        <Setter Property="ToolTip"
                Value="{Binding Converter={StaticResource converter}, RelativeSource={RelativeSource Mode=Self}}" />
        <Setter Property="ToolTipService.IsEnabled" 
                Value="True" />
        <Setter Property="ToolTipService.ShowOnDisabled" 
                Value="True" />
    </Style>

    <Style x:Key="toolTipTreeGridCell" TargetType="syncfusion:TreeGridCell">
        <Setter Property="ToolTip"
                Value="{Binding Converter={StaticResource converter}, RelativeSource={RelativeSource Mode=Self}}" />
        <Setter Property="ToolTipService.IsEnabled" 
                Value="True" />
        <Setter Property="ToolTipService.ShowOnDisabled" 
                Value="True" />
    </Style>
</Window.Resources>

<Grid>
    <syncfusion:SfTreeGrid Name="treeGrid"
                           AutoGenerateColumns="True"
                           ShowToolTip="True"
                           ExpanderCellStyle="{StaticResource toolTipTreeGridExpanderCell}"
                           CellStyle="{StaticResource toolTipTreeGridCell}"
                           ChildPropertyName="ReportsTo"
                           ParentPropertyName="ID"
                           ItemsSource="{Binding Employees}" />
</Grid>

Here, TreeGridCell and TreeGridExpanderCell ToolTip are displayed using the converter, where the converter returns the cell value based on the underlying property.

public class ToolTipConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var treeGridcell = value as TreeGridCell;
        string cellvalue = string.Empty;

        var column = treeGridcell?.ColumnBase?.TreeGridColumn;
        var treeGrid = column?.GetType()
                              .GetProperty("TreeGrid", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                              ?.GetValue(column) as SfTreeGrid;
        if (treeGridcell != null &&
            treeGridcell.ColumnBase != null &&
            !treeGridcell.ColumnBase.IsEditing)
        {
            string formattedValue = "";
            object value1 = null;

            if (treeGridcell.ColumnBase.ColumnElement != null)
            {
                value1 = treeGridcell.ColumnBase.ColumnElement.DataContext;
            }

            if (treeGridcell.ColumnBase.TreeGridColumn != null &&
                treeGrid != null &&
                treeGrid.View != null &&
                treeGridcell.ColumnBase.TreeGridColumn.MappingName != null)
            {
                var tempFormatValue = treeGrid.View
                                              .GetPropertyAccessProvider()
                                              .GetFormattedValue(value1, treeGridcell.ColumnBase.TreeGridColumn.MappingName);

                formattedValue = tempFormatValue?.ToString();
                cellvalue = formattedValue;
            }
        }
        return cellvalue;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The following screenshot shows the tooltip display for the disabled cell in TreeGrid, shows the tooltip display for the disabled cell in SfTreeGrid

Take a moment to peruse the WPF TreeGrid – ToolTip documentation, where you can find about tooltip with code examples.

Requirements to run the demo

Visual Studio 2015 and above versions

About

This demo shows how to show tooltip on the disabled cell in WPF SfTreeGrid.

Topics

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages