WPF菜单打开方向 [英] WPF Menu Open direction

查看:108
本文介绍了WPF菜单打开方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下菜单.

        <Menu>
        <MenuItem Header="Menu1">            
            <MenuItem Header="Sub1"/>
            <MenuItem Header="Sub2"/>
            <MenuItem Header="Sub3"/>
            <MenuItem Header="Sub4"/>
        </MenuItem>
        <MenuItem Header="Menu2" />
    </Menu>

子菜单打开时是向上还是向下,我有什么办法指定自己的方向?

The sub-menu when opened is either in an up or down direction, is there any way I can specify the direction my self?

我希望子菜单始终向上渲染,因为它本身的菜单位于窗口的底部.

I'd prefer the sub-menu to always render upwards since the menu it self is on the bottom of a window.

谢谢 托尼

推荐答案

该子菜单是使用Popup控件在内部实现的.默认模板将弹出窗口的位置设置为底部",如果有足够的空间,该菜单将下拉菜单,否则菜单将被下拉".

The submenu is implemented internally using a Popup control. The default template sets the Popup's placement to Bottom which will drop the menu down if there is enough room, otherwise the menu will be "dropped up".

您可以通过覆盖MenuItems的控件模板来覆盖此行为.您将需要将覆盖的弹出窗口的位置设置为顶部.

You can override this behavior by overriding the control template for your MenuItems. You will want to set your overridden Popup's Placement to Top.

http://msdn.microsoft.com上下载默认的Aero模板/en-us/library/aa972144.aspx 为例.

这篇关于WPF菜单打开方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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