Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF GradientBrush?

How Many type of gradient brushes are available like LinearGradientBrush, SolidColorBrush? and when we create a GradientStop how the offset works?

        LinearGradientBrush LGB = new LinearGradientBrush();
        LGB.StartPoint = new Point(0, 0);
        LGB.EndPoint = new Point(0, 1);
        LGB.GradientStops.Add(new GradientStop(Color.FromRgb(255,251,255) , 0));
        LGB.GradientStops.Add(new GradientStop(Color.FromRgb(206,207,222), 1));
        LGB.GradientStops.Add(new GradientStop(Color.FromRgb(0, 247, 0), 2));
        rect.Fill = LGB;

Why the third one "Color.FromRgb(0, 247, 0)" is not reflecting?

Please suggest,where i am wrong?

like image 451
Jaswant Agarwal Avatar asked Apr 26 '26 20:04

Jaswant Agarwal


1 Answers

The GradientStop.Offset property is a value which ranges from 0.0 to 1.0. From the MSDN documentation:

A value of 0.0 specifies that the stop is positioned at the beginning of the gradient vector, while a value of 1.0 specifies that the stop is positioned at the end of the gradient vector.

Change your second stop's offset to 0.5 and your third's to 1.0 and it should work.

like image 85
Matt Hamilton Avatar answered Apr 29 '26 09:04

Matt Hamilton