有什么方法可以使 WPF 菜单中的分隔符更窄吗?

发布于 2024-09-29 17:16:00 字数 261 浏览 1 评论 0原文

我注意到 WPF 菜单中默认分隔符的边距或高度似乎比其他一些应用程序(例如 Visual Studio 2010)稍大。我知道这些分隔符可以通过应用带有自定义 ControlTemplate 的新样式,但像往常一样,我正在寻找任何可能的方法来更改它,而无需手动重新定义控件的组成。

如果我所要求的不可能,如果有人可以提供权威且详尽的解释,我会接受答案。另外我想强调,我对有关如何重新定义 ControlTemplate 的讲座不感兴趣,因为我将其视为最后的手段,并且我已经知道如何实现这一点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

游魂 2024-10-06 17:16:00

aero.normalcolor MenuItem Separator 的样式如下所示:

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

您需要将此样式复制到 app.xaml 并更改 Margin="0,6,0,4" 以匹配您的偏好。

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.

苏佲洛 2024-10-06 17:16:00

我总是使用负边距:

编辑 2022-03-15: 自 Windows 10 推出以来不再有效。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文