我正在尝试使用Silverlight中的线性渐变变量填充椭圆(在.cs文件中)。这是我试过的......
newEllipse.Fill = ballBG;
但是,这会删除椭圆上已有的填充。我也试过......
newEllipse.Background = ballBG;
然而,它出现了这个错误...'System.Windows.Shapes.Ellipse'不包含'Background'的定义,也没有扩展方法'Background'接受类型'System.Windows的第一个参数。可以找到Shapes.Ellipse'(您是否缺少using指令或程序集引用?)
有关如何做的任何建议吗?
答案 0 :(得分:0)
拥有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;