C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Caution: When trying to nest a ToolBar within a ToolBarTray, you may need to simply edit the XAML. It may not work by dragging.
Band: On the ToolBar element, add a Band attribute. This is the vertical index, starting at 0, of the ToolBar.
BandIndex: This is the horizontal index of the ToolBar, starting at zero on the left. It goes up when two ToolBars are on the same line.
Example markup: XAML
<Window x:Class="WpfApplication11.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ToolBarTray HorizontalAlignment="Left" Height="74" Margin="10,10,0,0"
VerticalAlignment="Top" Width="497">
<ToolBar HorizontalAlignment="Right" Height="27"
Band="0" BandIndex="0">
<Button Content="In band 1" Height="22" VerticalAlignment="Top" Width="75"/>
<Button Content="Button" Height="22" VerticalAlignment="Top" Width="75"/>
</ToolBar>
<ToolBar HorizontalAlignment="Left" Height="27"
Band="1" BandIndex="0">
<Button Content="In band 2" Height="22" VerticalAlignment="Top" Width="75"/>
</ToolBar>
</ToolBarTray>
</Grid>
</Window>
Note: Some attributes on the above XAML, including the HorizontalAlignment ones are not necessary for the program to correctly work.
HorizontalAlignmentName: Please also assign a Name to the first ToolBar so it is easy to access from the Button_Click event handler.
NameExample markup 2: XAML
<ToolBar HorizontalAlignment="Right" Height="27" Band="0" Name="Bar1">
<Button Content="In band 1" Height="22" VerticalAlignment="Top" Width="75"
Click="Button_Click"/>
Tip: The BandIndex is the horizontal index, while the Band is the vertical index. This program makes this concept clear.
Example code: C#
using System.Windows;
namespace WpfApplication11
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// ... Change the title when this button is clicked.
this.Title = "Band: " + this.Bar1.Band.ToString() +
"; BandIndex: " + this.Bar1.BandIndex.ToString();
}
}
}
Thus: We position ToolBars within a ToolBarPanel using the Band and BandIndex attributes in XAML.