Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LinearGradientBrush and Background

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 ?

like image 711
wpflerner Avatar asked Sep 11 '11 20:09

wpflerner


People also ask

What is WPF LinearGradientBrush?

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.

How do you apply gradient color in xamarin form?

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.


1 Answers

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;
like image 107
Oltamor Avatar answered Oct 14 '22 11:10

Oltamor