开发者

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

开发者 https://www.devze.com 2023-01-21 06:30 出处:网络
I\'ve noticed that the margin or height 开发者_如何学Pythonof 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 2

I've noticed that the margin or height 开发者_如何学Pythonof 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.


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.


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

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

0

精彩评论

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