WPF样式学习:ToolBar的使用

时间:2022-04-23 02:09:53

隐藏拖动把手:

设置ToolBar属性 ToolBarTray.IsLocked="True",可以达到隐藏拖动把手的目的

private void ToolBar_Loaded(object sender, RoutedEventArgs e) { //去掉ToolBar右边默认的扩展图标 ToolBar toolBar = sender as ToolBar; var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement; if (overflowGrid != null) { overflowGrid.Visibility = Visibility.Collapsed; } var mainPanelBorder = toolBar.Template.FindName("MainPanelBorder", toolBar) as FrameworkElement; if (mainPanelBorder != null) { mainPanelBorder.Margin = new Thickness(0); } }

  <ToolBar x:Name="tbStuRelay"  Width="120" ToolBarTray.IsLocked="True" Background="#008ede" HorizontalAlignment="Stretch"  VerticalAlignment="Center"  VerticalContentAlignment="Center" Loaded="ToolBar_Loaded" MouseMove="ToolBar_MouseMove" Visibility="Collapsed">

</ToolBar>

WPF样式学习:ToolBar的使用