ToolBarTray

工具栏套件为您提供RadToolBarTray控件,该控件允许您托管多个RadToolBar元素在同一个托盘里。托盘处理其内部工具栏的位置、大小和顺序。它被分成带(行),每个带可以包含多个工具栏。

图1:RadToolBarTray概述

RadToolBarTray概述

定义ToolBarTray

的一个非常基本的定义RadToolBarTray控件的两个radtoolbar。

示例1:在XAML中定义托盘

              

图2:用radtoolbar填充RadToolBarTray

RadToolBarTray用RadToolBars填充

设置Band和BandIndex

RadToolBar控件公开乐队属性,该属性可用于定义托盘中工具栏的行。在当前频带中的位置(顺序)通过BandIndex属性。

下图显示了频带和频带索引如何影响托盘中工具栏的位置。

图3:RadToolBarTray波段和波段索引

RadToolBarTray波段和波段索引

默认为全部RadToolBar承载在托盘中的元素位于第一个波段(波段=0)。默认的频带索引是基于工具栏的集合索引加上当前频带位置。

例2:手动设置“Band”和“BandIndex”

< telerik: RadToolBarTray > < telerik: RadToolBar BandIndex = " 1 " > < telerik: RadButton内容=“按钮1 " / > < telerik: RadButton内容= "按钮2 " / > < telerik: RadButton内容= "按钮3 " / > < / telerik: RadToolBar > < telerik: RadToolBar BandIndex = " 0 " > < telerik: RadButton内容= "按钮4 " / > < telerik: RadButton内容= "按钮5 " / > < telerik: RadButton内容= "按钮6 " / > < / telerik: RadToolBar > < telerik: RadToolBar乐队= " 2 " > < telerik: RadButton内容= "按钮7 " / > < telerik: RadButton内容= "按钮8 " / >      

图4:带有Band和BandIndex集合的RadToolBars

RadToolBarTray用RadToolBars填充,展示Band和BandIndex属性

设置方向

默认情况下,RadToolBarTray将水平排列工具栏。同样,RadToolBar控件将对其项进行水平排序。要切换托盘和工具栏的方向,请设置取向的属性RadToolBarTray垂直

例3:设置方向

          

图4:垂直方向的RadToolBarTray

垂直方向的RadToolBarTray

在MVVM场景下使用RadToolBarTray

R1 2020 sp1版本,RadToolBarTray支持生成RadToolBars,当它的ItemsSource属性被设置。例4和5演示如何以MVVM方式实现与示例2中所示相同的结果。

例4:数据库模型和视图模型

公共类ToolBarButtonViewModel{公共字符串内容{get;设置;}}公共类ToolBarModel{公共ToolBarModel(){这个。ItemModels = new ObservableCollection();}公共ObservableCollection ItemModels {get;设置;} public int Band {get;设置;}公共int BandIndex {get;设置; } } public class MainViewModel { private ObservableCollection toolBarModels; public ObservableCollection ToolBarModels { get { if (this.toolBarModels == null) { this.toolBarModels = this.CreateToolBarModels(); } return toolBarModels; } } private ObservableCollection CreateToolBarModels() { return new ObservableCollection() { new ToolBarModel() { BandIndex = 1, ItemModels = new ObservableCollection() { new ToolBarButtonViewModel() {Content = "Button 1"}, new ToolBarButtonViewModel() {Content = "Button 2"}, new ToolBarButtonViewModel() {Content = "Button 2"}, }, }, new ToolBarModel() { BandIndex = 0, ItemModels = new ObservableCollection() { new ToolBarButtonViewModel() {Content = "Button 4"}, new ToolBarButtonViewModel() {Content = "Button 5"}, new ToolBarButtonViewModel() {Content = "Button 6"}, }, }, new ToolBarModel() { Band = 2, ItemModels = new ObservableCollection() { new ToolBarButtonViewModel() {Content = "Button 7"}, new ToolBarButtonViewModel() {Content = "Button 8"}, }, }, new ToolBarModel() { Band = 1, ItemModels = new ObservableCollection() { new ToolBarButtonViewModel() {Content = "Button 9"}, new ToolBarButtonViewModel() {Content = "Button 10"}, }, }, }; } }
公共类ToolBarButtonViewModel公共属性内容()作为字符串结束类公共类ToolBarModel公共子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{。内容= "按钮10"}}}}结束功能结束类

例5:在xaml中定义RadToolBarTray

<网格> <网格。    - >   <。DataContext>    
在本文中
Baidu
map