This is a migrated thread and some comments may be shown as answers.

Tooltip on Column title (header) GridView

1 Answer 313 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Veteran
Anton asked on 03 Nov 2020, 05:44 AM

Hello.

I want add ToolTip on GridViewHeaderCell, column created in code as

column = new GridViewDataColumn
                {
                    ColumnGroupName = args.ColumnDef.ColumnGroupName,                
                    DataMemberBinding = new Binding(args.ColumnDef.Member)
                    {
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    },
                    IsReadOnlyBinding = new Binding(args.ColumnDef.IsReadOnlyMember)
                    {
                        Converter = new NullToBooleanConverter {IsInverted = true}
                    },
                    Header = args.ColumnDef.Header,
                    HeaderCellStyle = TryFindResource("DataHeaderCellStyle") != null ? (Style)Resources["DataHeaderCellStyle"] : new Style(typeof(GridViewHeaderCell)),

                    IsVisible = true,
                    IsFilterable = false,
                };

                if (args.ColumnDef.ToolTip != null)
                    column.ToolTip = new ToolTip { Content = args.ColumnDef.ToolTip };

 

in xaml i added style

<Style x:Key="DataHeaderCellStyle" BasedOn="{StaticResource GridViewHeaderCellStyle}" TargetType="telerik:GridViewHeaderCell">
            <!--<Setter Property="ToolTipService.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content.Column.ToolTipText, Mode=OneWay}" />-->
            <Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Self}}"/>
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="TextWrapping" Value="Wrap"/>
                <Setter Property="FontSize" Value="12"/>
</Style>

 

If use <Setter Property="ToolTipService.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content.Column.ToolTipText, Mode=OneWay}" /> or <Setter Property="ToolTipService.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content.ToolTipText, Mode=OneWay}" /> this is don't work, no tooltip.

If use <Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Self}}"/> (seen here https://www.telerik.com/forums/tooltip-on-column-title) content of GridViewHeaderCell will be lost (on attachement).

How need set tooltip in style property?

If add event subscribe (as here https://www.telerik.com/forums/radgridview---tooltip-for-dynamically-created-column), will work...

ctor

{

    InitializeComponent();
    EventManager.RegisterClassHandler(typeof(GridViewHeaderCell), GridViewHeaderCell.MouseEnterEvent, new RoutedEventHandler(OnMouseEnterEvent));
}

        private void OnMouseEnterEvent(object sender, RoutedEventArgs e)
        {
            if (sender is GridViewHeaderCell cell && cell.Column.ToolTip != null)
            {
                cell.ToolTip = cell.Column.ToolTip;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 05 Nov 2020, 02:46 PM

Hello Anton,

The Content of the GridViewHeaderCell is a UI element and if you bind it to its ToolTip property, the tooltip will steal the Content because you cannot have the same UI element instances on two places in the UI. To achieve your requirement you can set the ToolTip property of the column directly to the string value.

column = new GridViewDataColumn
{
	// some other settings here
	ToolTip = "This is the column's tooltip."
};

And then use the following binding:

<Style TargetType="telerik:GridViewHeaderCell" x:Key="DataHeaderCellStyle">
	<Setter Property="telerik:RadToolTipService.ToolTipContent" Value="{Binding RelativeSource={RelativeSource Mode=Self},Path=Column.ToolTip}" />
</Style>

I've also attached a small example showing this approach. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Anton
Top achievements
Rank 1
Veteran
Answers by
Martin Ivanov
Telerik team
Share this question
or