views:

138

answers:

1
+2  Q: 

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?

+3  A: 

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.

Matt Hamilton
Thanks matt..It works fine
Jaswant Agarwal