在我的小型WPF程序中,我想在鼠标单击时在消息框中显示客户区域的“背景颜色”的名称....我该如何做?
系统:Win7(32位)/VS2008
谢谢。
系统:Win7(32位)/VS2008
谢谢。
您需要获取要获取颜色的元素的Background
对象。在鼠标单击事件中按如下方式操作:
注意:您必须检查刷子类型,基本上只有SolidColorBrush
才适用于简单颜色,因为渐变不是单一颜色。
示例:
Brush backgroundColor = LayoutRoot.Background;
if (backgroundColor is SolidColorBrush)
{
string colorValue = ((SolidColorBrush)backgroundColor).Color.ToString();
}