ToolBarTray内新行中的工具栏
本文关键字:工具栏 新行中 ToolBarTray | 更新日期: 2023-09-27 18:25:44
ToolBarTray中有两个工具栏。虽然它们可以放在一行中,但我想把每个工具栏放在新行中。我该怎么做?
<ToolBarTray VerticalAlignment="Top" Margin="0,20,70,0" Height="65">
<ToolBar Height="30" VerticalAlignment="Top" Background="LightGray" >
<Label>Name :</Label>
<TextBox Width="120"></TextBox>
<ComboBox Width="120" Margin="5,0,0,0">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
</ComboBox>
<Button Height="25" Width="80" Background="White" Margin="5,0,0,0">Search</Button>
<Label>This is a first ToolBar</Label>
<Button Height="25" Width="80" Background="White" Margin="5,0,0,0" ToolBar.OverflowMode="Always">Look for ..</Button>
</ToolBar>
<ToolBar Height="30" VerticalAlignment="Top" Background="LightGray">
<Label>Name :</Label>
<TextBox Width="120"></TextBox>
<ComboBox Width="120" Margin="5,0,0,0">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
</ComboBox>
</ToolBar>
</ToolBarTray>
来自MSDN:ToolBar.BandIndex属性:
工具栏在工具栏托盘中的位置取决于ToolBarTray.Orientation、Band和BandIndex属性。什么时候"方向"设置为"水平",标注栏表示工具栏托盘。当"方向"为"垂直"时,标注栏表示一列工具栏托盘的。
在这种情况下,您需要将ToolBarTray.Orientation属性设置为Vertical
:
<ToolBarTray Orientation="Vertical"
VerticalAlignment="Top" Margin="0,20,70,0" Height="65">
<etc />
</ToolBarTray>
而且,不要忘记ToolBar.Band和ToolBar.BandIndex属性:
如果未显式设置此属性,则其值由工具栏在工具栏托盘中的设置顺序。例如如果在ToolBarTray中放置两个工具栏而不设置标注栏和BandIndex属性,两个工具栏的Band值都将为0。对于第一个工具栏,BandIndex的值将为0,对于第二个工具栏。