在我的应用程序中,我有一堆ContextMenus,我希望它们都有相同的外观,这是非常基本的,但它使用资源来设置HighlightBrushKey和ControlBrushKey,它们都是SystemColors。它看起来是这样的:
<ContextMenu Padding="0" Background="Transparent">
<ContextMenu.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
</ContextMenu.Resources>
<MenuItem Header="Delete"/>
<MenuItem Header="Modify"/>
</ContextMenu>这里没有太花哨的东西,但我找不到一种方法来把它放在一种风格中,我想做的是这样的:
<Style TargetType="ContextMenu">
<Setter Property="Padding" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Resources">
<Setter.Value>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Setter.Value>
</Setter>
</Style>如何将资源放入样式中?(如果可能的话……)
谢谢!
发布于 2011-08-31 18:45:36
无法通过设置器设置Resources,因为它不是依赖属性。将相关资源添加到Style.Resources或覆盖Template并在其中添加资源。不过,范围可能是有限的。
<Style TargetType="ContextMenu">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
<Setter Property="Padding" Value="0" />
<Setter Property="Background" Value="Transparent" />
</Style>https://stackoverflow.com/questions/7255416
复制相似问题