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

Bind the Custom HeaderTemplate name to the MappingName

Thread ID:

Created:

Updated:

Platform:

Replies:

140876 Nov 12,2018 07:00 PM UTC Nov 13,2018 09:58 AM UTC Xamarin.Forms 1
loading
Tags: SfDataGrid
Mark Tannehill
Asked On November 12, 2018 07:00 PM UTC

I want to customize my headers to be different colors on my SfDataGrid. The trouble is, that I have to update my header names based on some other inputs on my tool.

I am able to get the HeaderTemplate to update to my correct initial settings but cannot seem to update the value easily.

What I'm hoping is that I can bind my internal label text to the MappingName, might look something like this in XAML, but I'm looking for the C# version. 

<syncfusion:SfDataGrid.Columns>
    <syncfusion:GridTextColumn MappingName="OrderID">
        <syncfusion:GridTextColumn.HeaderTemplate>
            <DataTemplate>
                <Label x:Name="OrderID" Text="{Binding MappingName}" TextColor="Black" />
            </DataTemplate>
        </syncfusion:GridTextColumn.HeaderTemplate>
    </syncfusion:GridTextColumn>
</syncfusion:SfDataGrid.Columns> Here is kinda what I'm looking for... 

  private static DataTemplate HeaderTemplate(Color color) {
            return new DataTemplate(() => {
                var label = new Label() { Text = (#WHAT GOES HERE?#), BackgroundColor = color };
                return new ViewCell { View = label };
            });
        }



Suhasini  Suresh [Syncfusion]
Replied On November 13, 2018 09:58 AM UTC

Hi Mark, 
 
Thanks for contacting Syncfusion Support. 
 
We checked your query, please find the below code snippet to achieve your requirement to set the binding for the TextProperty in code behind. 
private static DataTemplate HeaderTemplate(Color color) 
{ 
    return new DataTemplate(() => { 
        var label = new Label() 
        { 
            BackgroundColor = color 
        }; 
        label.SetBinding(Label.TextProperty, "MappingName"); 
        return new ViewCell { View = label }; 
    }); 
} 
 
Regards,    
Suhasini  


CONFIRMATION

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

;