Add color to WPF grid from code behind

  • Thread starter Thread starter DNB
  • Start date Start date
D

DNB

I would like to add this color #E7EBF7 to my WPF data grid

I know that I can add light blue color using following:

Grid b = new Grid();

b.Background = System.Windows.Media.Brushes.LightBlue;



but how to add specific color (i.e. #E7EBF7 )



Thanks

DNB
 
DNB,

Just use a SolidColorBrush, like so:

// Create the color first.
System.Windows.Media.Color color = System.Windows.Media.Color.FromRgb((byte)
0xE7, (byte) 0xEB, (byte) 0xF7);

// Create the brush.
System.Windows.Media.SolidColorBrush brush = new
System.Windows.Media.SolidColorBrush(color);

// Set the background.
b.Background = brush;
 
Thanks

DNB
Nicholas Paldino said:
DNB,

Just use a SolidColorBrush, like so:

// Create the color first.
System.Windows.Media.Color color =
System.Windows.Media.Color.FromRgb((byte) 0xE7, (byte) 0xEB, (byte) 0xF7);

// Create the brush.
System.Windows.Media.SolidColorBrush brush = new
System.Windows.Media.SolidColorBrush(color);

// Set the background.
b.Background = brush;


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

DNB said:
I would like to add this color #E7EBF7 to my WPF data grid

I know that I can add light blue color using following:

Grid b = new Grid();

b.Background = System.Windows.Media.Brushes.LightBlue;



but how to add specific color (i.e. #E7EBF7 )



Thanks

DNB
 
Back
Top