WPF GradientBrush?

How many types of gradient brushes are available as LinearGradientBrush, SolidColorBrush? and when we create a GradientStop, how does the offset work?

        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 does the third β€œColor.FromRgb (0, 247, 0)” not reflect?

Please suggest where am I mistaken?

+3
source share
1 answer

The value of GradientStop.Offset is a value that varies from 0.0 to 1.0. From the MSDN documentation:

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

Change the second stop offset to 0.5 and the third to 1.0, and it should work.

+5

Source: https://habr.com/ru/post/1717608/


All Articles