Toolbar wpf

Diego Alvarez 101 Reputation points
2020-07-02T18:19:38.333+00:00

Hi. How do I remove the default separator of the toolbar in WPF?

Thank you.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
{count} votes

Accepted answer
  1. DaisyTian-1203 11,626 Reputation points
    2020-07-03T01:21:49.353+00:00

    The Xaml code is:

      <ToolBarTray Background="White" x:Name="my">  
                <ToolBar Band="1" BandIndex="1" ToolBarTray.IsLocked="True" Loaded="ToolBar_Loaded">  
                    <Button>  
                        <Image Source="toolbargraphics\cut.png" />  
                    </Button>  
                    <Button>  
                        <Image Source="toolbargraphics\copy.png" />  
                    </Button>  
                    <Button>  
                        <Image Source="toolbargraphics\paste.png" />  
                    </Button>  
                </ToolBar>  
      
                <ToolBar Band="2" BandIndex="1" Margin="0 50 ">  
                    <Button>  
                        <Image Source="toolbargraphics\cut.png" />  
                    </Button>  
                    <Separator/>  
                    <Button>  
                        <Image Source="toolbargraphics\copy.png" />  
                    </Button>  
                    <Button>  
                        <Image Source="toolbargraphics\paste.png" />  
                    </Button>  
                </ToolBar>  
            </ToolBarTray>  
    

    The cs code is:

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

    Here is the comparison diagram:
    11397-%E6%89%B9%E6%B3%A8-2020-07-06-102113.png


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.