WPF學習日誌 ~ ToolBar ~
這篇利用簡單的程式碼來熟悉一下ToolBar的使用方式,同樣的,也利用對照的方式,做了簡單的XAML Code來讓大家對照,下面就來看看程式碼吧
下面是XAML Code,由於blogger這邊不適合貼XAML Code,我用圖片來貼
Class Window1
Dim dp As DockPanel
Dim tb(3) As ToolBar
Dim tbTray As ToolBarTray
Dim txtBody As TextBox
Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
dp = New DockPanel
Me.Content = dp
tbTray = New ToolBarTray
dp.Children.Add(tbTray)
DockPanel.SetDock(tbTray, Dock.Top)
txtBody = New TextBox
txtBody.AcceptsReturn = True
txtBody.Background = Brushes.AliceBlue
txtBody.VerticalScrollBarVisibility = ScrollBarVisibility.Auto
dp.Children.Add(txtBody)
''設定最後加入的項目填滿剩餘的空間
dp.LastChildFill = True
For i As Integer = 0 To tb.Length - 1
tb(i) = New ToolBar
''設定ToolBar的文字,通常不使用
tb(i).Header = "TB" & i.ToString
For j As Integer = 0 To 3
Dim btn As New Button
btn.Content = "ToolBar-" & i & " Button No." & j
Dim sp As New Separator
''加入按鈕
tb(i).Items.Add(btn)
''加入分隔線
tb(i).Items.Add(sp)
Next
''設定ToolBar在哪一列上面,
''BandIndex可以設定在這一列上的哪一個位置
tb(i).Band = i
''把ToolBar放到ToolBarTray中
tbTray.ToolBars.Add(tb(i))
Next
End Sub
End Class
下面是XAML Code,由於blogger這邊不適合貼XAML Code,我用圖片來貼
留言