相关疑难解决方法(0)

以隐式样式设置 SystemColors 覆盖

在我的应用程序中,我有一堆 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>
Run Code Online (Sandbox Code Playgroud)

这里没有什么太奇特的,但我找不到一种方法来将它置于一种风格中,我想做的是:

<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>
Run Code Online (Sandbox Code Playgroud)

如何将资源融入风格中?(如果可能的话……)

谢谢!

wpf resources xaml styles

2
推荐指数
1
解决办法
3294
查看次数

标签 统计

resources ×1

styles ×1

wpf ×1

xaml ×1