Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to make a Separator within a WPF menu more narrow?

I've noticed that the margin or height of the default Separator as it is styled in the menus in WPF seems to be slightly larger than some other applications such as Visual Studio 2010. I know that these Separators can be re-templated by applying a new style with a custom ControlTemplate but like always I'm looking for any possible way to change this without having to manually re-define the composition of the control.

If what I'm asking for isn't possible I will accept an answer if somebody can provide an authoritative and exhaustive explanation. Also I would like to stress that I'm not interested in a lecture about how to redefine the ControlTemplate as I'm treating that as the last resort and I'm already aware of how to accomplish this.

like image 450
jpierson Avatar asked Oct 26 '10 15:10

jpierson


2 Answers

The style for the aero.normalcolor MenuItem Separator looks like this:

<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}"
       TargetType="{x:Type Separator}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Separator}">
                <Grid SnapsToDevicePixels="true" Margin="0,6,0,4">
                    <Rectangle Height="1"
                               Margin="30,0,1,1"
                               Fill="#E0E0E0"/>
                    <Rectangle Height="1"
                               Margin="30,1,1,0"
                               Fill="White"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

You would need to copy this style to your app.xaml and change the Margin="0,6,0,4" to match your preferences.

like image 144
Daniel Moore Avatar answered Oct 05 '22 19:10

Daniel Moore


I always use negative margin: <Separator Margin="0,-4" />.

Edit 2022-03-15: Does not work anymore since Windows 10 came out.

like image 32
Nytmo Avatar answered Oct 05 '22 21:10

Nytmo