# ToolBarTray

The toolbars suite provides you with the `RadToolBarTray` control that allows you to host several `RadToolBar` elements in the same tray. The tray handles the position, size, and order of toolbars inside of it. It is divided by bands (rows) and each band can contain multiple toolbars.

> caption RadToolBarTray overview

![RadToolBarTray overview](https://www.telerik.com/products/wpf/documentation/assets/b31dc9b80d37a939401c808541c1c547/radtoolbartray-overview-0.png)

## Defining ToolBarTray

The following example shows a very basic definition of the `RadToolBarTray` control with two RadToolBars.

**Example 1: Define the tray in XAML**

```XAML
<telerik:RadToolBarTray VerticalAlignment="Center" Width="460">
    <telerik:RadToolBar>
        <telerik:RadButton Content="Button 1" />
        <telerik:RadButton Content="Button 2 " />
        <telerik:RadButton Content="Button 3" />
    </telerik:RadToolBar>
    <telerik:RadToolBar>
        <telerik:RadButton Content="Button 1" />
        <telerik:RadButton Content="Button 2 " />
    </telerik:RadToolBar>
</telerik:RadToolBarTray>
```

> caption RadToolBarTray populated with RadToolBars

![RadToolBarTray populated with RadToolBars](https://www.telerik.com/products/wpf/documentation/assets/abfb5e7c6bfb78d4eb395b6afa729601/radtoolbartray-overview-1.png)

## Setting Band and BandIndex

The `RadToolBar` control exposes a `Band` property that can be used to define the row of the toolbar in the tray. The position (the order) in the current band is controlled via the `BandIndex` property of the toolbar.

The following picture shows how the band and band index affect the positions of the toolbars in the tray.

> caption RadToolBarTray band and BandIndex

![RadToolBarTray Band and BandIndex](https://www.telerik.com/products/wpf/documentation/assets/8993d61e578b952d00ae0dd5bf2bfe00/radtoolbartray-overview-2.png)

> By default all `RadToolBar` elements hosted in the tray are positioned in the first band (Band=0). The default band index is the based on the collection index of the toolbar plus the current band position.

**Example 2: Setting Band and BandIndex manually**

```XAML
<telerik:RadToolBarTray>
    <telerik:RadToolBar BandIndex="1">
        <telerik:RadButton Content="Button 1" />
        <telerik:RadButton Content="Button 2 " />
        <telerik:RadButton Content="Button 3" />
    </telerik:RadToolBar>
    <telerik:RadToolBar BandIndex="0">
        <telerik:RadButton Content="Button 4" />
        <telerik:RadButton Content="Button 5 " />
        <telerik:RadButton Content="Button 6" />
    </telerik:RadToolBar>
    <telerik:RadToolBar Band="2">
        <telerik:RadButton Content="Button 7" />
        <telerik:RadButton Content="Button 8 " />
    </telerik:RadToolBar>
    <telerik:RadToolBar Band="1">
        <telerik:RadButton Content="Button 9" />
        <telerik:RadButton Content="Button 10 " />
    </telerik:RadToolBar>
</telerik:RadToolBarTray>
```

> caption RadToolBars with band and BandIndex set

![RadToolBarTray populated with RadToolBars demonstrating the Band and BandIndex properties](https://www.telerik.com/products/wpf/documentation/assets/e4b5442cd03396d5290d54b7d8c2f4d2/radtoolbartray-overview-3.png)

## Setting Orientation

By default, the `RadToolBarTray` will order the toolbars horizontally. Also, the RadToolBar controls will order its items horizontally. To switch the orientation of the tray and the toolbars set the `Orientation` property of `RadToolBarTray` to `Vertical`.

**Example 3: Setting Orientation**

```XAML
<telerik:RadToolBarTray Orientation="Vertical" VerticalAlignment="Center" Width="460">
    <telerik:RadToolBar>
        <telerik:RadButton Content="B1" />
        <telerik:RadButton Content="B2 " />
        <telerik:RadButton Content="B3" />
    </telerik:RadToolBar>
    <telerik:RadToolBar>
        <telerik:RadButton Content="B4" />
        <telerik:RadButton Content="B5 " />
        <telerik:RadButton Content="B6" />
    </telerik:RadToolBar>
</telerik:RadToolBarTray>
```

> caption RadToolBarTray with vertical orientation

![RadToolBarTray with Vertical Orientation](https://www.telerik.com/products/wpf/documentation/assets/62d1178fceade00afa6b579dce926cd7/radtoolbartray-overview-4.png)

## Use the RadToolBarTray in an MVVM scenario

Since the **R1 2020 SP1** release, the RadToolBarTray supports generating RadToolBars when its ItemsSource property is set. **Examples 4 and 5** demonstrate how to achieve the same result shown in Example 2 in an MVVM manner.

**Example 4: Sаmple models and viewmodels**

```C#
public class ToolBarButtonViewModel
{
    public string Content { get; set; }
}

public class ToolBarModel
{
    public ToolBarModel()
    {
        this.ItemModels = new ObservableCollection<ToolBarButtonViewModel>();
    }

    public ObservableCollection<ToolBarButtonViewModel> ItemModels { get; set; }

    public int Band { get; set; }

    public int BandIndex { get; set; }
}

public class MainViewModel
{
    private ObservableCollection<ToolBarModel> toolBarModels;

    public ObservableCollection<ToolBarModel> ToolBarModels
    {
        get
        {
            if (this.toolBarModels == null)
            {
                this.toolBarModels = this.CreateToolBarModels();
            }

            return toolBarModels;
        }
    }

    private ObservableCollection<ToolBarModel> CreateToolBarModels()
    {
        return new ObservableCollection<ToolBarModel>()
                                    {
                                        new ToolBarModel()
                                        {
                                            BandIndex = 1,
                                            ItemModels = new ObservableCollection<ToolBarButtonViewModel>()
                                            {
                                                new ToolBarButtonViewModel() {Content = "Button 1"},
                                                new ToolBarButtonViewModel() {Content = "Button 2"},
                                                new ToolBarButtonViewModel() {Content = "Button 2"},
                                            },
                                        },

                                        new ToolBarModel()
                                        {
                                            BandIndex = 0,
                                            ItemModels = new ObservableCollection<ToolBarButtonViewModel>()
                                            {
                                                new ToolBarButtonViewModel() {Content = "Button 4"},
                                                new ToolBarButtonViewModel() {Content = "Button 5"},
                                                new ToolBarButtonViewModel() {Content = "Button 6"},
                                            },
                                        },

                                        new ToolBarModel()
                                        {
                                            Band = 2,
                                            ItemModels = new ObservableCollection<ToolBarButtonViewModel>()
                                            {
                                                new ToolBarButtonViewModel() {Content = "Button 7"},
                                                new ToolBarButtonViewModel() {Content = "Button 8"},
                                            },
                                        },
                                        new ToolBarModel()
                                        {
                                            Band = 1,
                                            ItemModels = new ObservableCollection<ToolBarButtonViewModel>()
                                            {
                                                new ToolBarButtonViewModel() {Content = "Button 9"},
                                                new ToolBarButtonViewModel() {Content = "Button 10"},
                                            },
                                        },
                                    };
    }
}
```

```VB.NET
	Public Class ToolBarButtonViewModel
		Public Property Content() As String
	End Class

	Public Class ToolBarModel
		Public Sub New()
			Me.ItemModels = New ObservableCollection(Of ToolBarButtonViewModel)()
		End Sub

		Public Property ItemModels() As ObservableCollection(Of ToolBarButtonViewModel)

		Public Property Band() As Integer

		Public Property BandIndex() As Integer
	End Class

	Public Class MainViewModel
		Private _toolBarModels As ObservableCollection(Of ToolBarModel)

		Public ReadOnly Property ToolBarModels() As ObservableCollection(Of ToolBarModel)
			Get
				If Me._toolBarModels Is Nothing Then
					Me._toolBarModels = Me.CreateToolBarModels()
				End If

				Return _toolBarModels
			End Get
		End Property

		Private Function CreateToolBarModels() As ObservableCollection(Of ToolBarModel)
			Return New ObservableCollection(Of ToolBarModel)() _
				From {
					New ToolBarModel() With {
						.BandIndex = 1,
						.ItemModels = New ObservableCollection(Of ToolBarButtonViewModel)() From {
							New ToolBarButtonViewModel() With {.Content = "Button 1"},
							New ToolBarButtonViewModel() With {.Content = "Button 2"},
							New ToolBarButtonViewModel() With {.Content = "Button 2"}
						}
					},
					New ToolBarModel() With {
						.BandIndex = 0,
						.ItemModels = New ObservableCollection(Of ToolBarButtonViewModel)() From {
							New ToolBarButtonViewModel() With {.Content = "Button 4"},
							New ToolBarButtonViewModel() With {.Content = "Button 5"},
							New ToolBarButtonViewModel() With {.Content = "Button 6"}
						}
					},
					New ToolBarModel() With {
						.Band = 2,
						.ItemModels = New ObservableCollection(Of ToolBarButtonViewModel)() From {
							New ToolBarButtonViewModel() With {.Content = "Button 7"},
							New ToolBarButtonViewModel() With {.Content = "Button 8"}
						}
					},
					New ToolBarModel() With {
						.Band = 1,
						.ItemModels = New ObservableCollection(Of ToolBarButtonViewModel)() From {
							New ToolBarButtonViewModel() With {.Content = "Button 9"},
							New ToolBarButtonViewModel() With {.Content = "Button 10"}
						}
					}
				}
		End Function
	End Class
```

**Example 5: Defining the RadToolBarTray in xaml**

```XAML
<Grid>
    <Grid.Resources>
        <DataTemplate DataType="{x:Type local:ToolBarButtonViewModel}">
            <telerik:RadButton Content="{Binding Content}" />
        </DataTemplate>

        
        
        <Style x:Key="ToolBarStyle" TargetType="telerik:RadToolBar" >
            <Setter Property="ItemsSource" Value="{Binding ItemModels}" />
            <Setter Property="Band" Value="{Binding Band}" />
            <Setter Property="BandIndex" Value="{Binding BandIndex}" />
        </Style>
    </Grid.Resources>
    <Grid.DataContext>
        <local:MainViewModel />
    </Grid.DataContext>

    <telerik:RadToolBarTray ItemsSource="{Binding ToolBarModels}" ItemContainerStyle="{StaticResource ToolBarStyle}" />
</Grid>
```
