In WPF, how can I make the ToolBar.Header disappear?
I read in two different books that in WPF the ToolBar.Header property does nothing:
- Windows Presentation Foundation, Unleashed by Adam Nathan, p. 119
- Pro WPF with VB 2008, p. 650
However, I dynamically create ToolBar objects this way (tbtToolBar is actually ToolBarTray defined in Xaml, vm is the ViewModel window):
foreach (IToolBarViewModel toolBarViewModel in vm.ToolBars)
{
ToolBar toolBar = new ToolBar();
toolBar.DataContext = toolBarViewModel;
// Bind the Header Property
Binding headerBinding = new Binding("Header");
toolBar.SetBinding(ToolBar.HeaderProperty, headerBinding);
// Bind the Items Property
Binding itemsBinding = new Binding("Items");
toolBar.SetBinding(ToolBar.ItemsSourceProperty, itemsBinding);
tbtToolBar.ToolBars.Add(toolBar);
}
And the title property is explicitly displayed in the label as the first item in the toolbar. This is not the behavior I want. I would like to use the title as the title in the ToolBars dropdown when the user right click on the ToolBarTray as described in the books.
So, I tried to get rid of the header by setting:
toolBar.HeaderTemplate = new DataTemplate();
This works, but there is now a small unsightly white space in the toolbar.
- Is there a way to make the title invisible without a space?
- Why are the books clearly wrong? Has something changed between now and then?
0
a source to share