我试着用系统颜色给我的窗口上色,但是当我这样做的时候:
<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“,这也不会被接受为有效值。但文本显示为“"MenuBarColorKey”不是有效值....“
我怎样才能纠正这个错误呢?
谢谢你的帮忙
迈克尔
编辑:@AwkwardCoder
对不起,阅读已经有几年了,我刚开始在stackoverflow中写作,所以我不能评论或投票。
你是正确的。使用笔刷时,它可以正常工作。非常感谢!
但是我引用了来自Zack Peterson的实用程序的名称,如
"wpf -如何使用正确的Windows系统颜色?“
在那里我没有找到扩展名"Brush“。这个实用程序对我很有效。
发布于 2014-09-26 17:56:41
这里有两个问题。首先,您希望对Brush属性使用Color,其次,您尝试使用Color作为资源键。
如果要将其用作资源,则需要使用SystemColors.MenuBarBrushKey
Background="{DynamicResource {x:Static SystemColors.MenuBarBrushKey}}"或者,您可以直接使用它,然后使用SystemColors.MenuBarBrush
Background="{x:Static SystemColors.MenuBarBrush}"您会发现SystemColors为每种颜色提供了4个静态属性
XxxxColor为您提供类结构XxxxColorKey为您提供类structureXxxxBrush为您提供类classXxxxBrushKey为您提供ResourceKey to SolidColorBrush类发布于 2014-09-26 17:47:43
根据MSDN page,没有MenuBarColor,只有MenuBarBrush
https://stackoverflow.com/questions/26056479
复制相似问题