WPF - 如何设置菜单控件的样式以删除左边距? [英] WPF - How to style the menu control to remove the left margin?

查看:39
本文介绍了WPF - 如何设置菜单控件的样式以删除左边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将默认菜单控件添加到我的用户控件中.我需要设置菜单样式以删除包含图标或复选框空间的左边距.我该怎么做?

I have added a default menu control to my user control. I need to style the menu to remove the left margin containing the space for the icon or checkbox. How can I do this?

XAML:

<Menu>
    <MenuItem Header="MyMenu" FontSize="10">
        <MenuItem Header="Options..." />
        <MenuItem Header="About" />
    </MenuItem>
</Menu>  

它目前像任何其他开箱即用的菜单控件一样呈现:

It currently renders like any other Menu control out of the box:

我不想要菜单项左侧的边距或列.这通常用于图标等.

I don't want the margin or column to the left of the menu items. This is typically used for icons etc.

推荐答案

这不是很直接,但是你需要创建一个 MenuItemStyle,通过 Expression Blend 最简单:

It's not very straight forward, but you need to create a MenuItemStyle, easiest through Expression Blend:

<Menu>
    <MenuItem Header="MyMenu" Style="{DynamicResource MenuItemStyle1}">
        <MenuItem Header="Options..." />
        <MenuItem Header="About" />
    </MenuItem>
</Menu> 

它创建了一组极其冗长的模板和样式,您需要编辑菜单项以删除网格的固定宽度第一列,然后在 SubMenuBorder ContentControl 模板中删除形成背景阴影的矩形.我附上了一个删除了边距的示例项目.在此处下载示例项目.

It creates an extremely verbose set of templates and styles, and you need to edit the menu item to remove the fixed width first column of the grid, then in the SubMenuBorder ContentControl template, remove the rectangles which form the background shading. I've attached a sample project with margins removed. Download sample project here.

这篇关于WPF - 如何设置菜单控件的样式以删除左边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆