我有一个silverlight应用程序,在应用程序中的某个地方包含以下行:
txtMelding.Foreground = new SolidColorBrush(Colors.Black);和
txtMelding.Foreground = new SolidColorBrush(Colors.Gray);稍后,我想有一个IF,只要前景色是黑色或灰色就会检查。多么?
发布于 2010-11-23 16:49:57
我发现了怎么做:
if (((SolidColorBrush)txtMelding.Foreground).Color == Colors.Gray)发布于 2010-11-23 15:16:33
if (((SolidBrush)txtMelding.Foreground).Color == Colors.Gray)
{
// the color is gray
}发布于 2010-11-23 15:19:37
你需要将前景笔刷转化为SolidBrush -假设你知道它总是一个实心笔刷:
SolidBrush brush = (SolidBrush) txtMelding.Foreground;
if (brush.Color == Colors.Gray)
{
...
}如果您不知道它始终是一个SolidBrush,您可以使用as
SolidBrush brush = txtMelding.Foreground as SolidBrush;
if (brush != null && brush.Color == Colors.Gray)另一方面,颜色不应该反映你状态的某些方面吗?(在设计方面)对此做出反应可能比对UI外观做出反应要好得多。
https://stackoverflow.com/questions/4253626
复制相似问题