WPF ToolBar: how to remove grip and overflow

后端 未结 6 2404
有刺的猬
有刺的猬 2020-12-07 14:29

In a nested WPF ToolBarPanel-ToolBar-Menu we want to get rid of the grip handle to the left and the overflow area to the right. they are both grayed out, but we\'d like them

6条回答
  •  无人及你
    2020-12-07 15:01

    The grip can be removed by setting the attached property ToolBarTray.IsLocked="True" on the ToolBar.

    To remove the Overflow ToggleButton, you will have to remove it in a custom ControlTemplate as sixlettervariables suggests, which if you have blend or can download the Blend 3 Preview is not overly difficult.

    You could also just hide the button in the loaded event of the ToolBar, though whichever route you take, you should also set the attached property ToolBar.OverflowMode="Never" on the ToolBar's menu, so that items cannot accidentally overflow into an unreachable area.

    
        
            
                
                
            
        
    
    

    And set the Overflow ToggleButton to collapsed:

    private void ToolBar_Loaded(object sender, RoutedEventArgs e)
    {
        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();
        }
    }
    

提交回复
热议问题