question

DiegoAlvarez-3139 avatar image
0 Votes"
DiegoAlvarez-3139 asked DiegoAlvarez-3139 commented

Toolbar wpf

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

Thank you.

windows-wpf
image.png (223 B)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I had edited the answer for your question.

0 Votes 0 ·

1 Answer

DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered DiegoAlvarez-3139 commented

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




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.