在Silverlight中填充椭圆(在.cs文件中)

本文关键字:cs 文件 Silverlight 填充 | 更新日期: 2023-09-27 18:24:54

我正试图在Silverlight中(在.cs文件中)用线性梯度变量填充椭圆。以下是我尝试过的。。。

        newEllipse.Fill = ballBG;

但是,这将删除椭圆上已经存在的填充。我也试过。。。

        newEllipse.Background = ballBG;

然而,它出现了这个错误…"System.Windows.Shapes.Ellipse不包含"Background"的定义,也找不到接受类型为"System.Windows.Ships.Ellipse"的第一个参数的扩展方法"Background"(是否缺少using指令或程序集引用?)

有什么建议吗?

在Silverlight中填充椭圆(在.cs文件中)

使用SolidColorBrush:时

Ellipse redEllipse = new Ellipse();
redEllipse.Height = 100;
redEllipse.Width = 300;           
SolidColorBrush redBrush = new SolidColorBrush();
redBrush.Color = Colors.Red;
SolidColorBrush blackBrush = new SolidColorBrush();
blackBrush.Color = Colors.Black;
redEllipse.StrokeThickness = 4;
redEllipse.Stroke = blackBrush;
redEllipse.Fill = redBrush;

更新对于你的LinearGradientBrush,我发现了这个:

LinearGradientBrush myBrush=new LinearGradientBrush ();
myBrush.SetValue(LinearGradientBrush.StartPointProperty, ("0,0"));
myBrush.GradientStops(1).Offset = 0.5;
myBrush.SetValue(LinearGradientBrush.EndPointProperty, ("1,1"));
myBrush.GradientStops(0).Color = Colors.Red;
myBrush.GradientStops(1).Color = Colors.Green;
newEllipse.Fill = myBrush;