I'm trying to paint a background of my WPF window using LinearGradientBrush, however my code doesn't work. Here is the code
LinearGradientBrush gradientBrush = new LinearGradientBrush( Color.FromArgb(0, 209, 227, 250), Color.FromArgb(0, 170, 199, 238), new Point(0.5, 0), new Point(0.5, 1));
Background = gradientBrush;
Unforunatelly my window is still white. Is it possible to change the Background color of the window using code behind ?
A linear gradient brush paints an area with a linear gradient. The LinearGradientBrush object represents a linear gradient brush. The default value linear gradient value is diagonal. The StartPoint and EndPoint properties of the LinearGradientBrush represent the start and end points of a gradient.
To create a horizontal linear gradient, create a LinearGradientBrush object and set its StartPoint to (0,0) and its EndPoint to (1,0). Then, add two or more GradientStop objects to the LinearGradientBrush. GradientStops collection, that specify the colors in the gradient and their positions.
You are setting the alpha setting also. Use this instead since you want the colour:
LinearGradientBrush gradientBrush = new LinearGradientBrush( Color.FromRgb( 209, 227, 250), Color.FromRgb(170, 199, 238), new Point(0.5, 0), new Point(0.5, 1));
Background = gradientBrush;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With