我如何检查是否存在控制与否的特定属性?

时间:2013-04-03 07:14:19

标签: wpf wpf-controls

如何检查标签背景

if([Label has any color don't do anything]){  
    if (turn == Players.p1)
                    {
                        label.Background = Brushes.Red;
                        turn = Players.p2;
                    }
                    else
                    {
                        label.Background = Brushes.Green;
                        turn = Players.p1;
                    }
    }

1 个答案:

答案 0 :(得分:1)

您可以通过检查其Background,或者可能是null

来检查空Transparent

所以要么

if (label.Background == null)

或者

if (label.Background == Brushes.Transparent)