Silverlight小技巧--如何得到Rectangle对象背景色

今天在编写代码的时候要用到一个功能,就是点击某一个Rectangle时判断背景色并作相应的处理,结果Fill对象不能直接得到背景色的颜色值,网上找资料后终于解决了问题,方法如下:

Color seatSelectedColor = Colors.Red;

 Rectangle seat = seatContent.FindName("X" + x.ToString() + "Y" + y.ToString()) as Rectangle;
                    //如果没被选择则选择上,否则就取消选择
                    if ((seat.Fill as SolidColorBrush).Color == seatSelectedColor)
                    {
                        seat.Fill = null;
                        //取消选择执行的操作

                    }
                    else {
                        seat.Fill = new SolidColorBrush(seatSelectedColor);
                        //选择后执行的操作
                    }

 

你可能感兴趣的:(silverlight)