WPF工具栏中的下拉菜单 [英] Dropdown Menu in WPF Toolbar

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

问题描述

在WPF中有一些布局方面的麻烦-我正在使用工具栏来容纳一组控件,其中大多数是Button,而其中一个(即将成为)某种下拉菜单.在WinForms中,ToolStripDropDownButton是完美的.但是,我似乎无法找出在WPF中复制此行为的最佳方法.

Having some layout frustrations in WPF- I'm using a ToolBar to house a set of controls, most of which are Buttons and one of which is (going to be) some sort of dropdown menu. In WinForms, the ToolStripDropDownButton was perfect; however, I can't seem to figure out the best way to replicate this behavior in WPF.

有什么想法吗?

推荐答案

您可以尝试放置菜单&工具栏内的MenuItem.我不得不在界面的各个部分(除了传统菜单之外)使用Menu和MenuItem树来获得下拉菜单行为.您可以调整菜单的控制模板,以根据自己的喜好雕刻外观,并完全放弃香草菜单的外观.

You could try placing a Menu & MenuItem inside the Toolbar. I've had to use Menu's and MenuItem trees in various parts of the interface (besides classical menus) to get the dropdown menu behavior. You can tweak the control template of the menu to sculpt the look and feel to look however you like and completely abandon the vanilla menu look and feel.

这里有一些XAML展示了一个简单的实现:

Here's some XAML to show a simple implementation:

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel>
    <ToolBar>
            <Button Content="Button1"></Button>
            <Button Content="Button2"></Button>
            <Menu>
                <MenuItem Header="Menu">
                    <MenuItem Header="MenuItem1"/>
                </MenuItem>
            </Menu>
    </ToolBar>
</StackPanel>

这篇关于WPF工具栏中的下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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