|  | 
 
| 在WPF中,您可以使用LinearGradientBrush或RadialGradientBrush来创建渐变颜色。这些画笔可以用作填充或描边的画笔,以创建具有渐变颜色的形状或控件。 
 例如,以下代码创建了一个具有线性渐变填充的矩形:
 
 Rectangle rect = new Rectangle();
 rect.Width = 200;
 rect.Height = 100;
 
 LinearGradientBrush brush = new LinearGradientBrush();
 brush.StartPoint = new Point(0, 0);
 brush.EndPoint = new Point(1, 1);
 
 GradientStop stop1 = new GradientStop(Colors.Red, 0.0);
 GradientStop stop2 = new GradientStop(Colors.Yellow, 0.5);
 GradientStop stop3 = new GradientStop(Colors.Blue, 1.0);
 
 brush.GradientStops.Add(stop1);
 brush.GradientStops.Add(stop2);
 brush.GradientStops.Add(stop3);
 
 rect.Fill = brush;
 上面的代码创建了一个宽度为200,高度为100的矩形,并使用线性渐变画笔进行填充。渐变画笔从左上角开始,到右下角结束,并包含三个渐变停靠点:红色(偏移量为0.0),黄色(偏移量为0.5)和蓝色(偏移量为1.0)。
 | 
 |