WPF ellipse颜色设置
<Ellipse Name="ellipse1" Width="20" Height="20" Cursor="Hand" ToolTip="警示灯" Margin="35,12,723,512" Fill="Red">
这是我在xaml中设置ellipse颜色为红色。
我现在想在xaml.cs中判断当前这个ellipse1是不是为红色,如果是红色我要把它变成绿色,请问这个该怎么写? WPF ELLIPSE
[解决办法]
后台获取ellipse1.Fill,得到的是一个Brush对象,
bool isRed = (ellipse1.Fill as SolidColorBrush).Color.Equals(Colors.Red);
if (isRed)
{
ellipse1.Fill = new SolidColorBrush(Colors.Green);
}