We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

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>

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

Is there anything I'm missing or doing wrong?

Thank you very much for your help!


Victor

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.  


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> 



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.  


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> 



Please let us know if you have any query. 

Regards, 
Muthukumar K 


Loader.
Up arrow icon