C# 带有 WPF 菜单控件的下拉列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/196840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:37:41  来源:igfitidea点击:

Drop Down List with WPF Menu Controls

c#.netwpf

提问by smaclell

I am looking for a way to add a drop down list in WPF to a menu. This used to be really easy in winforms and so I am expecting you experts to know just now to do it in WPF. Thanks.

我正在寻找一种将 WPF 中的下拉列表添加到菜单的方法。这曾经在 winforms 中非常容易,所以我希望您的专家现在知道在 WPF 中做到这一点。谢谢。

Sorry if this is a bad question, it is late and I don't want to think.

对不起,如果这是一个不好的问题,已经晚了,我不想思考。

采纳答案by Jobi Joy

It is very easy to add any UIElement to any control, You can just add Combobox to a Menu control and create menu as bellow.

将任何 UIElement 添加到任何控件非常容易,您只需将 Combobox 添加到 Menu 控件并创建如下菜单即可。

<Menu>
    <MenuItem Header="File">
        <MenuItem Header="Open"/>
        <MenuItem Header="Close"/>
        <Separator/>
        <ComboBox Width="85" Height="21.96" />
    </MenuItem>
</Menu>

回答by Alan Le

While this is very easy to do as Jobi Joy has shown, I think it has horrible usability. The Menu control supports multiple levels of menu items and I would go down that route for UI consistency.

虽然这很容易做到,正如 Jobi Joy 所展示的那样,但我认为它的可用性很差。Menu 控件支持多级菜单项,为了 UI 一致性,我会沿着这条路线走下去。