[solved] Change only header color

Hi,

I want to change the header color, but only the header color. I cannot find the base-style to use in BasedOn.


        <Style TargetType="sf:GridHeaderCellControl" x:Key="headerStyle" BasedOn="sf:">

            <Setter Property="Foreground" Value="Black"/>

        </Style>


Or is there another way to achieve my need?


Cheers!


7 Replies

BR Babita Rawat March 16, 2024 10:40 AM UTC

Hii ..To change the header color, you can specify the header background color directly within the defined style. Below I explain how you can modify your XAML code:


xml

copy the code

<style TargetType='sf:GridHeaderCellControl' x:Key='headerStyle'>

      <setter property="background" value="your desired color"/>

</style>

Replace Your DesiredColor with the color you want for the header background. This way the color of the header will be changed.


hope this helps

ALSO YOU CAN TRY  how to become a-power bi developer



BO Boon March 16, 2024 10:54 PM UTC

Hey,

yeah that ist right, but the base style is then overwritten. Font type, font size, ...

I want to change the color only. That is why I am trying to figure out what the name of the syncfusion style is to use it in the "based on" parameter.


Cheers 



SP Sreemon Premkumar Muthukrishnan Syncfusion Team March 18, 2024 03:21 PM UTC

Hi Boon,


As you mentioned, the base style was overwritten, and you observed changes in the font type and font size. We suspect that you applied a specific theme to the SfDataGrid, causing the base style to be altered. To overcome this issue, you must add the namespace of the themes as a ResourceDictionary in the App.xaml file. We have prepared a sample based on your requirements; please find it attached. We have applied the MaterialDark theme for the SfDataGrid.


Code in App.Xaml:


<Application.Resources>

    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>

            <ResourceDictionary Source="/Syncfusion.Themes.MaterialDark.WPF;component/SfDataGrid/SfDataGrid.xaml" />

        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

</Application.Resources>



Code in MainWindow.XAML:


<Style TargetType="syncfusion:GridHeaderCellControl" x:Key="headerStyle" BasedOn="{StaticResource SyncfusionGridHeaderCellControlStyle}">

     <Setter Property="Foreground" Value="Green"/>
</Style>



Regards,

Sreemon Premkumar M.


Attachment: HeaderRowStyleDemo_9a011db2.zip


BO Boon March 18, 2024 09:41 PM UTC

Hey, thank you. Works as intended.

But I have a problem with this solution. I don't want to use style keys. That is possible and works. This way I can apply styles for all my SfDataGrids globally.

But if I use the SkinManager in den constructor of my view (SfSkinManager.SetTheme(this, new Theme("Windows11Light"));) the global style in my app.xaml (Application.Resources > ResourceDictionary > Style...) is overwritte on runtime.

Is there any way I can force the theme to load before the app.xaml-style is applied?


If this is not possible I can go with the style-key. Work


Thanks!



SP Sreemon Premkumar Muthukrishnan Syncfusion Team March 19, 2024 02:00 PM UTC

Hi Boon,

To obtain the base style along with your style customization for the header, you must add the namespace of the themes in the ResourceDictionary. This approach allows you to access the base style for the header exclusively. Importing the namespace directly into the ResourceDictionary within MainWindow.XAML, rather than in App.XAML, confines the style application to DataGrids within MainWindow.XAML only.

Apart from this, there are no alternatives but to utilize style keys for this customization.

Regards,
Sreemon Premkumar M.



BO Boon March 21, 2024 05:47 AM UTC

Thank you =)



SP Sreemon Premkumar Muthukrishnan Syncfusion Team March 21, 2024 07:38 AM UTC

Hi Boon,


Glad that your issue is resolved!! Please let us know if you require any additional assistance. We are happy to help you.

Regards,
Sreemon Premkumar M.


Loader.
Up arrow icon