2010-10-05 171 views
1

在我的小型WPF程序中,我希望在消息框中单击鼠标时显示客户区的“背景颜色”的名称....我怎样才能做它?如何获取WPF背景的颜色

系统:Win7(32位)/ VS2008

谢谢。

+1

客户区.... – 2010-10-05 17:38:26

回答

9

您需要获取要获取其颜色的元素的背景对象。在你的鼠标点击事件中这样做:

注意:您必须检查哪种笔刷类型,基本上SolidColorBrush只会真正适用,因为渐变不会是简单的颜色。

示例: Brush backgroundColor = LayoutRoot.Background;

 if (backgroundColor is SolidColorBrush) 
     { 
      string colorValue = ((SolidColorBrush)backgroundColor).Color.ToString(); 
     }