HeaderToolTipTemplate with HeaderText instead of MappingName
Hi!
I'm trying to define a DataTemplate for the HeaderToolTip in a SfDataGrid. After setting the ShowHeaderToolTip to true it displays the MappingName ("OrderID"). Now I'd like to show the HeaderText ("Order Number") and some other information instead. For example like this:
I tried to create a DataTemplate like this but it only shows an empty Box:
<DataTemplate x:Key="TemplateDataGridHeaderToolTip">
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=HeaderText}" />
</DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=HeaderText}" />
</DataTemplate>
Now I'm creating the columns in Code Behind and add the template like this:
newColumn.ShowHeaderToolTip = true;
DataTemplate templateDataGridHeaderToolTip = (DataTemplate)TryFindResource("TemplateDataGridHeaderToolTip");
if (templateDataGridHeaderToolTip != null) { newColumn.HeaderToolTipTemplate = templateDataGridHeaderToolTip; }
if (templateDataGridHeaderToolTip != null) { newColumn.HeaderToolTipTemplate = templateDataGridHeaderToolTip; }
Is there anything I'm missing or doing wrong?
Thank you very much for your help!
Victor
SIGN IN To post a reply.
2 Replies
MK
Muthukumar Kalyanasundaram
Syncfusion Team
June 13, 2017 03:44 AM UTC
Hi Victor,
Thank you for contacting Syncfusion support.
We have analyzed your code. The HeaderTooltip header text shows as empty because while setting RelativeSource as Self will bind the same control as a source for current binding. Hence, it will search for the path “HeaderText” given in the current binding, inside the textblock, there is no property named as “HeaderText”, so it will return null value will be displayed. For your reference, we have attached the link in below.
Link: https://msdn.microsoft.com/en-us/library/system.windows.data.relativesource.self(v=vs.110).aspx
You can re-solve this problem by binding the HeaderText as shown like below code snippet:
Code Snippet: Xaml
|
<Window.Resources>
<DataTemplate x:Key="TemplateDataGridHeaderToolTip">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="User.png" Grid.Column="0" Height="20"/>
<TextBlock Text="{Binding Path=HeaderText}" Grid.Column="1" />
</Grid>
</DataTemplate>
</Window.Resources>
|
Sample: http://www.syncfusion.com/downloads/support/forum/130900/ze/HeaderTextTooltip_DataGrid-1983995214
Please let us know if you have any query.
Regards,
Muthukumar K
MK
Muthukumar Kalyanasundaram
Syncfusion Team
June 13, 2017 03:53 AM UTC
Hi Victor,
Thank you for contacting Syncfusion support.
We have analyzed your code. The HeaderTooltip header text shows as empty because while setting RelativeSource as Self will bind the same control as a source for current binding. Hence, it will search for the path “HeaderText” given in the current binding, inside the textblock, there is no property named as “HeaderText”, so it will return null value will be displayed. For your reference, we have attached the link in below.
Link: https://msdn.microsoft.com/en-us/library/system.windows.data.relativesource.self(v=vs.110).aspx
You can re-solve this problem by binding the HeaderText as shown like below code snippet:
Code Snippet: Xaml
|
<Window.Resources>
<DataTemplate x:Key="TemplateDataGridHeaderToolTip">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="User.png" Grid.Column="0" Height="20"/>
<TextBlock Text="{Binding Path=HeaderText}" Grid.Column="1" />
</Grid>
</DataTemplate>
</Window.Resources>
|
Sample: http://www.syncfusion.com/downloads/support/forum/130900/ze/HeaderTextTooltip_DataGrid-1983995214
Please let us know if you have any query.
Regards,
Muthukumar K
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
VD Victor Dienstbier
- Jun 9, 2017 08:41 AM UTC
- Jun 13, 2017 03:53 AM UTC