开发者

Setting SystemColors overrides in an implicit style

In my application, I have a bunch of ContextMenus, and I want them all to have the same look, which is quite basic, but it uses the resources to set HighlightBrushKey and ControlBrushKey, which are SystemColors. It looks like this:

<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>

Nothing too fancy here开发者_如何学JAVA, but I can't find a way to put it in a style, what I would like to do is something along the lines of:

<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>

How do you put resources in a style? (if it is at all possible...)

Thanks!


You cannot set Resources via a setter as it is not a dependency property. Add the relevant resources to the Style.Resources or override the Template and add resources there. The scope may be limited though.


<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜