how to set DataGridHeader background code behind.

BitSmithy 2,226 Reputation points
2021-08-27T08:49:17.45+00:00

Hello,

How to set DataGridHeader background color code behind.
I tried such code, in AutogeneratigColumns event handler

        Setter s = new Setter();
        s.Property = BackgroundProperty;
        s.Value = new SolidColorBrush(Colors.Red);
        //e.Column.HeaderStyle.Setters.Add(s);

        Style ss = new Style();
        ss.Setters.Add(s);

        e.Column.HeaderStyle = ss;

but I failed.

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,511 Reputation points
    2021-08-27T12:49:20.327+00:00

    You can change the colors for example in Page_Loaded :

      this.Resources["DataGridColumnHeaderBackgroundColor"] = Windows.UI.Color.FromArgb(128, 0, 255, 0);  
      this.Resources["DataGridColumnHeaderHoveredBackgroundColor"] = Windows.UI.Color.FromArgb(255, 0, 128, 128);  
      this.Resources["DataGridColumnHeaderPressedBackgroundColor"] = Windows.UI.Color.FromArgb(255, 0, 255, 128);  
    

    127145-uwp-datagrid.gif


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.