我正在尝试使用系统颜色为我的窗口着色,但是当我这样做时:
<Menu
Width="Auto"
Height="20"
Background="{DynamicResource {x:Static SystemColors.MenuBarColor}}"/>
我得到一个8位数的六位数。我的程序只接受3或6个数字的颜色。执行程序始终会显示错误消息
System.Windows.Markup.XamlParseException: Zeilennummer "11" und Zeilenposition "4"
von "Beim Festlegen der Eigenschaft" System.Windows.Controls.Panel.Background
"wurde eine Ausnahme ausgelöst.". ---> System.ArgumentException: "#FFF0F0F0" ist
kein gültiger Wert für die Eigenschaft "Background".
如果我使用“MenuBarColorKey”,则不会将此作为vaild值接受。但随后文本中的“MenuBarColorKey”不是有效值....'
我该如何纠正?
感谢您的帮助
迈克尔
编辑: @AwkwardCoder
很抱歉,已经读了好几年了,我刚开始写stackoverflow,所以我不能评论或投票。
你是对的。用刷子工作。非常感谢!
但是我提到了实用程序的名称
中显示了Zack Peterson“wpf - 如何使用正确的Windows系统颜色?”
在那里我没有找到扩展名“Brush”。这个实用程序对我有用。
答案 0 :(得分:3)
这里有两个问题。首先,您要对Color
属性使用Brush
,然后尝试使用Color
作为资源键。
如果您想将其用作资源,则需要使用SystemColors.MenuBarBrushKey
Background="{DynamicResource {x:Static SystemColors.MenuBarBrushKey}}"
或者您可以直接使用它,然后您应该使用SystemColors.MenuBarBrush
Background="{x:Static SystemColors.MenuBarBrush}"
您会发现SystemColors
为每种颜色提供了4个静态属性
XxxxColor
为您提供Color
结构XxxxColorKey
为您提供ResourceKey
至Color
结构XxxxBrush
为您提供SolidColorBrush
课程XxxxBrushKey
为您ResourceKey
提供SolidColorBrush
课程答案 1 :(得分:0)
根据MSDN page,没有MenuBarColor
,有一个MenuBarBrush