Is it possible to remove this button in the ToolBar if they are not required in this situation?

Toolbar

    1 answer 1

    WPF is good because all the elements in it have their own style, which is very easy to change!

    1. Create an empty element, just write in the XAML <ToolBar/> .
    2. In the constructor (the window where we see our application) click on our element with the right mouse button.
    3. Click in the drop-down menu "Edit Template" - "Edit Copy." We will have this window:

    Edit window

    1. Specify in this window the name of the style, as well as the path where it will be created.
    2. You will have created the entire design of this control, which you can easily edit! Let's remove the button:
      • We need to find an element named OverflowGrid , this is a regular Grid ( <Grid x:Name="OverflowGrid" HorizontalAlignment="Right"> ). You can edit it, you can hide it, or you can delete it and everything connected with it. I will personally hide, I will add just Visibility="Collapsed" .
      • After hiding this Grid, you will see that there will be an indent on the right, it should also be removed. It is located at the element named MainPanelBorder . We find it and see that it refers to the ToolBarMainPanelBorderStyle style, we find it and see <Setter Property="Margin" Value="0,0,11,0"/> , set the value to 0 or delete the string altogether.

    That's it, now we can apply this style to any ToolBar and it will be without a button:

    Result

    In this simple way, you can change the style of any control in WPF. Good luck in programming!


    Another way (as for me, not very good, because we work with styles through code) [ source ].

    1. We sign our ToolBar on the Loaded event.
    2. In the handler, we also execute what we did through XAML:

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