Change background colour of the SfDataGrid header.

Hello everyone,

I am sure this is fairly simple but i can't seem to figure it out. How can i programmatically change the background colour of the header of the SfDataGrid?

I am coding in Xamarin.Forms C# and I am creating all the UI elements in the code rather than in the .xaml page.

Thanks.

6 Replies

VR Vigneshkumar Ramasamy Syncfusion Team August 20, 2018 07:30 AM UTC

Hi Constantinos Demetriou 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query with “Changing header background programmatically” and you requirement can achieved by writing custom style class deriving from DataGridStyle and assign it to the SfDataGrid.GridStyle property. Override the GetHeaderBackgroundColor in custom style to customize the header background. We have prepared a sample for the same and please find the code snippet and sample form below link. 
 
 
  private void Button_Clicked(object sender, EventArgs e) 
        { 
            dataGrid.GridStyle = new CustomStyle(); 
        } 
 
 
   public class CustomStyle : DataGridStyle 
    { 
        public CustomStyle() 
        { 
 
        } 
        public override Color GetHeaderBackgroundColor() 
        { 
            return Color.Red; 
        } 
    } 
 
 
Sample Link:HeaderBackground
 
 
Please let us know if this helpful 
 
Regards 
Vigneshkumar R 



CO Coz August 20, 2018 08:21 AM UTC

Hi Vigneshkumar,

Yes, this is exactly what i was looking for.

Thank you very much.


VR Vigneshkumar Ramasamy Syncfusion Team August 20, 2018 08:40 AM UTC

Hi Constantinos Demetriou, 
 
We glad to know that your requirement has been achieved. Please get in touch if you required further assistance on this. 
   
Regards 
Vigneshkumar R 



UN Unknown July 15, 2019 02:16 PM UTC

Hi 

I just came across this thread during my UI framework evaluation for a client o mine. The solution  they plan to implement will need also to display data in a datagrid 
and targets Xamarin.Forms.

So I started playing around with the SfDataGrid control. It was easy to just get a datagrid displayed, but difficulties start arise when it comes to customization. Actually I can't find the way how to style column headers to have a background color of my choice (blue) and the text color for  example (white) in XAML. I used XAML in context of many WPF projects. What I was expecting is to have possibility to write something like

<Style x:Key="justakeyname" TargetType="syncf:HeaderPresenter">
     <Setter Property="BackgroundColor" Value="Blue"/>
     <Setter Property="Color" Value="White"/>
</Style>

which fits well with Xaml. The only solution I found to achieve the header styling is to implement a class that derives from DataGridStyle. I personally don't like this solution so I ask you if I'm missing something in the documentation?

Thanks



SP Subburaj Pandian Veluchamy Syncfusion Team July 16, 2019 01:28 PM UTC

Hi Massimo, 
 
Thank you for the update. 
 
Currently we are analyzing your requirement of “Styling the DataGrid Header from Xaml” instead of using GridStyle (code behind) as in other platforms. We will validate and update you the further details in two business days (July 18, 2019). We appreciate your patience until then. 
 
Regards,
Subburaj Pandian V 



SP Subburaj Pandian Veluchamy Syncfusion Team July 19, 2019 09:02 AM UTC

Hi Massimo,  
  
Thank you for your patience. 
 
 As per the DataGrid implementation in Xamarin.Forms, we didn’t provided support style the DataGrid Header from Xaml. So, for now you can customize using DataGrid style from code behind only. We will consider the same in future.

UG link: https://help.syncfusion.com/xamarin/sfdatagrid/styles 

Please let us know, if you have any concern. 
 
Regards,
Subburaj Pandian V    


Loader.
Up arrow icon