Is there any way to hide a cell's tool tip when it's defined at the column level like so?
When ToolTipValue is null or empty, the tool tip still comes up, just without any content. I'd prefer if it wasn't displayed at all.
<telerik:GridViewDataColumn DataMemberBinding="{Binding CellValue}"> <telerik:GridViewDataColumn.ToolTipTemplate> <DataTemplate> <TextBlock Text="{Binding ToolTipValue}" /> </DataTemplate> </telerik:GridViewDataColumn.ToolTipTemplate></telerik:GridViewDataColumn>4 Answers, 1 is accepted
A similar scenario has been discussed in the following forum thread. Could you please give the suggested approaches a try and let me know if any of them works for you?
I will be looking forward to your reply.
Regards,
Dilyan Traykov
Progress Telerik
Alternatively, you can also try the approach suggested in this StackOverflow thread.
Regards,
Dilyan Traykov
Progress Telerik
Neither of those helped. Here's what I had to do for anyone else looking for a solution:
I set the grid view column's cell style like so, so that the cell is not hit test visible when the binding is null or empty, and can therefore not open a tool tip.
<telerik:GridViewDataColumn.CellStyle> <Style TargetType="telerik:GridViewCell"> <Style.Triggers> <DataTrigger Binding="{Binding ToolTipValue}" Value ="{x:Static system:String.Empty}" > <Setter Property="IsHitTestVisible" Value="False"/> </DataTrigger> <DataTrigger Binding="{Binding ToolTipValue}" Value ="{x:Null}" > <Setter Property="IsHitTestVisible" Value="False"/> </DataTrigger> </Style.Triggers> </Style> </telerik:GridViewDataColumn.CellStyle>Unfortunately, this is quite verbose and must be repeated for every column. At least there's no code behind, but this seems like a lot to have to add to get tool tips to not look ridiculous when empty. Can you think of something a bit more succinct?
Better yet, is there any chance we can get a ToolTipBinding property added to GridViewDataColumn? I currently need 17 lines of xaml to properly set up a tool tip on a cell.
<telerik:GridViewDataColumn.ToolTipTemplate> <DataTemplate> <TextBlock Text="{Binding ToolTipValue}" /> </DataTemplate></telerik:GridViewDataColumn.ToolTipTemplate><telerik:GridViewDataColumn.CellStyle> <Style TargetType="telerik:GridViewCell"> <Style.Triggers> <DataTrigger Binding="{Binding ToolTipValue}" Value ="{x:Static system:String.Empty}" > <Setter Property="IsHitTestVisible" Value="False"/> </DataTrigger> <DataTrigger Binding="{Binding ToolTipValue}" Value ="{x:Null}" > <Setter Property="IsHitTestVisible" Value="False"/> </DataTrigger> </Style.Triggers> </Style> </telerik:GridViewDataColumn.CellStyle>With a ToolTipTemplate property, you can reduce this to a single line for us.
ToolTipBinding="{Binding ToolTipValue}"
Thank you for sharing your solution with the community.
I see, however, one possible drawback to using such an approach - the cells will no longer be editable.
My best suggestion would be to instead define an implicit style targeting the GridViewDataColumn (please note that this is not recommended in other use-cases) and specify the following ToolTipTemplateSelector for it:
<Style TargetType="telerik:GridViewDataColumn"> <Setter Property="ToolTipTemplateSelector"> <Setter.Value> <my:TooltipTemplateSelector> <my:TooltipTemplateSelector.NormalTemplate> <DataTemplate> <TextBlock Text="{Binding ToolTipValue}" /> </DataTemplate> </my:TooltipTemplateSelector.NormalTemplate> </my:TooltipTemplateSelector> </Setter.Value> </Setter></Style>public class TooltipTemplateSelector : DataTemplateSelector{ public DataTemplate NormalTemplate { get; set; } public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (string.IsNullOrWhiteSpace((item as ItemType).ToolTipValue)) // replace this with your custom type { return null; } return NormalTemplate; }}Please note that you can get rid of the NormalTemplate property and dynamically construct the templates based on the item's type.
Please let me know whether using a similar approach would work for you.
I also want to inform you that, as per your request, I've logged a new feature request in our feedback portal regarding a new ToolTipBinding property. If this request generates enough votes, we will consider introducing it in future releases.
Regards,
Dilyan Traykov
Progress Telerik