今天在编写代码的时候要用到一个功能,就是点击某一个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);
                        //选择后执行的操作
                    }

 

相关文章:

  • 2021-07-19
  • 2021-11-17
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-10-11
  • 2022-02-15
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2021-12-27
相关资源
相似解决方案