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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid: how to bind the header of a column to a ViewModel?

Thread ID:





109854 Jul 8,2013 01:07 PM UTC Mar 19,2014 10:43 AM UTC WinRT 4
Tags: SfDataGrid
Andreas Myka
Asked On July 8, 2013 01:07 PM UTC

Is there any way to bind the header of a column to a property of the ViewModel?

I tried 
<syncfusion:GridTextColumn MappingName="ColumnName"
                                               HeaderText="{Binding ColumnNameLabel}" />

but that fails.

Is there a way to do that?

Jai Ganesh S [Syncfusion]
Replied On July 9, 2013 07:25 AM UTC

Hi Andreas,

Thanks for contacting syncfusion support.


We have analyzed your query.You can achieve the requirement by setting ViewModel as source value for the binding. We have created a simple sample to achieve this requirement and please check the sample under the following location,


Sample: http://www.syncfusion.com/downloads/Support/DirectTrac/110157/Headerbinding-1493656320.zip


Please let us know if you need further assistance.


Thank you,

Jai Ganesh S

Andreas Myka
Replied On July 9, 2013 08:24 AM UTC

Works great. Thanks for the fast and helpful reply!


Replied On March 17, 2014 08:02 PM UTC

Can you please provide an example of binding the header text without using a static resource?

In my situation I need to bind the heading text to a property on the data templates data context, the view model cannot be instantiated within XAML and the heading text value needs to change as the view model property is updated.
I have tried using various binding paths including element name etc but I can't seem to get it going. Any help would be appreciated.

Ashok N [Syncfusion]
Replied On March 19, 2014 10:43 AM UTC

Hi Jason,

You can achieve your requirement by using ElementName Binding as shown in the following code snippet.


                <syncfusion:GridTextColumn MappingName="EmployeeId" HeaderText="{Binding ElementName=datagrid, Path=DataContext.CustomHeaderText, Mode=TwoWay}"/>


We have created a sample to achieve this requirement and please check the following sample link. 



Please let us know if you require further assistance 




This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon