WPF FAQ - Menu

How can I 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 the SeparatorStyleKey property. 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.

[XAML]

<Style x:Key='{x:Static MenuItem.SeparatorStyleKey}' TargetType='Separator'>
  <Setter Property='OverridesDefaultStyle' Value='true' />
  <Setter Property='Template'>
    <Setter.Value>
      <ControlTemplate TargetType='{x:Type Separator}'>
        <Border Width='30' Height='4' Margin='4' Background='Red'/>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
Permalink
How do I enable the mnemonics (underlines) being displayed when an application is launched ?

Usually the underline appears only after you press the Alt Key, but you can enable it by changing the Operating System Settings. On Windows XP, Right Click ‘Desktop’ to bring up the Display Properties Dialog, then click on the ‘Appearance’ tab and finally on the ‘Effects’ Button and uncheck the checkbox ‘Hide Underlined letters for keyboard navigation until I press the ALT Key’.

Permalink