Export (0) Print
Expand All

How to: Style a Separator Used as a Menu Item

Separator controls inside Menu elements appear differently from Separator controls outside a Menu. When you create a Menu with a Separator the control automatically applies the Style identified by SeparatorStyleKey. Styles are placed in resource dictionaries and are searched for by their keys. To change the Style of a Separator inside a Menu, you must use the SeparatorStyleKey property to create your new Style. The following example demonstrates this.

Example

<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
    <Setter Property="OverridesDefaultStyle" Value="true" />
     <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Separator}">
                <Image Width="50" Height="30" Source="data\separator.png"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

For the complete sample see Menu Styles Sample.

See Also

Reference

MenuItem

Other Resources

Menu Sample

Community Additions

ADD
Show:
© 2015 Microsoft