WPF ToolBar: how to remove grip and overflow

Solution 1:

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.

<ToolBarPanel DockPanel.Dock="Top">
    <ToolBar ToolBarTray.IsLocked="True" Loaded="ToolBar_Loaded">
        <Menu ToolBar.OverflowMode="Never">
            <MenuItem Header="File" />
            <MenuItem Header="New" />
        </Menu>
    </ToolBar>
</ToolBarPanel>

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();
    }
}

Solution 2:

You can use Blend to rather simply override the ControlTemplate for the ToolBarPanel, Menu, or ToolBar.

  1. Right click on the ToolBar and select Edit Template
  2. From Edit Template, select Edit a Copy
  3. I recommend adding the copy to a Resource Dictionary
  4. Click Ok

You'll now be editing the control template for the ToolBarPanel, and can set the visibility to Collapsed for the grip and overflow signal. You can rinse and repeat for the other controls. It is a bit time consuming, but isn't terribly hard with Blend.

Solution 3:

You can "remove" the overflow without supplying a new control template by setting the ToolBar to have negative right margins (and throw in a negative left margin so it doesn't look odd with rounded left edges but square right edges). Then, add ClipToBounds="True" to the ToolBarPanel which will cut off the edges of the toolbar which are now sticking outside the panel's area.

<ToolBarPanel Grid.Row="0" ClipToBounds="True">
    <ToolBar ToolBarTray.IsLocked="True" Margin="-5,0,-13,0" Padding="5,0,0,0">
    . . .