等价于WPF中的ToolStripDropDownButton吗? [英] ToolStripDropDownButton equivalent in WPF?
问题描述
我是WPF技术的新手.我已经在WinForms中开发了大约6年.
I'm very newbie to the WPF technology. I've been developing in WinForms for around 6 years.
现在,我想通过学习WPF在我的技能上迈出一大步.我正在阅读MSDN中的入门指南,而作为个人练习,我正在尝试将WinForms UI的结构转换为其等效的WPF UI.
Now I would like to advance one big step in my skills by learning WPF. I'm reading the introduction guides in MSDN, while as a personal exercise I'm trying to translate the sructure of a WinForms UI to its WPF UI equivalent.
这是我想在WPF中重现的WinForms控件结构的简单模型:
This is a simple mockup of the WinForms controls structure that I would like to reproduce in WPF:
My problem is trying to reproduce the equivalent control/behavior for the ToolStripDropDownButton control.
在 工具栏 ,但是我没有找到在工具栏内添加下拉按钮的方法.
In the Windows Forms Controls and Equivalent WPF Controls article, Microsoft just says that the equivalent control for a ToolStripDropDownButton is a ToolBar...with composition. I don't understand at all what it means about "with composition". I've been reading and experimenting with the Toolbar, but I didn't found the way to add a dropdown button thing inside the toolbar.
我的问题:有人可以指导我或向我展示如何在工具栏内添加下拉按钮的简短示例?.
My question: someone could guide me or show me a brief example of how can I add a drop down button thing inside a Toolbar?.
推荐答案
您可以在Toolbar
中放入Menu
. Menu
包含一些MenuItem
.每个MenuItem
都有一个Header
内容,可以是文本或其他元素.此外,每个MenuItem
都可以具有一些嵌套或MenuItem
.例如,要具有这样的菜单结构:
You can put a Menu
in Toolbar
. A Menu
contains some MenuItem
. Each MenuItem
has a Header
which is it's content and can be a text or other elements. Also each MenuItem
can have some nested or MenuItem
s. For example, to have a menu structure like this:
您可以使用以下代码:
<ToolBar>
<Menu Background="#00000000">
<MenuItem >
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock>Menu 1</TextBlock>
<Path VerticalAlignment="Center" Margin="8,2,0,0"
Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</StackPanel>
</MenuItem.Header>
<MenuItem Header="Menu 1-1" >
<MenuItem Header="Menu 1-1-1"/>
<MenuItem Header="Menu 1-1-2"/>
</MenuItem>
<MenuItem Header="Menu 1-2"/>
<MenuItem>
<MenuItem.Header><TextBox Width="100"/></MenuItem.Header>
</MenuItem>
<MenuItem>
<MenuItem.Header><DatePicker Width="100"/></MenuItem.Header>
</MenuItem>
</MenuItem>
<MenuItem >
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock>Menu 2</TextBlock>
<Path VerticalAlignment="Center" Margin="8,2,0,0"
Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</StackPanel>
</MenuItem.Header>
<MenuItem Header="Menu 2-1"/>
<MenuItem Header="Menu 2-2"/>
<MenuItem Header="Menu 2-3"/>
</MenuItem>
<MenuItem Header="Menu 3"/>
</Menu>
</ToolBar>
这篇关于等价于WPF中的ToolStripDropDownButton吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!