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

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

问题描述

在 WPF 中遇到一些布局问题 - 我使用工具栏来容纳一组控件,其中大部分是按钮,其中一个是(将要成为)某种下拉菜单.在 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.

有什么想法吗?

推荐答案

您可以尝试放置一个 Menu &工具栏中的 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天全站免登陆