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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi. How do I remove the default separator of the toolbar in WPF?
Thank you.
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: