I have read in two different books that in WPF, the ToolBar.Header property doesn't do anything:
- Windows Presentation Foundation Unleashed by Adam Nathan, pg. 119
- Pro WPF with VB 2008, pg. 650
However, I'm creating my ToolBar objects dynamically like this (tbtToolBar is actually a ToolBarTray defined in the Xaml, vm is the window's ViewModel):
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 Header property clearly shows up in a label as the first item in the toolbar. This is not the behavior I want. I would like to use the Header as a title in a drop-down list of ToolBars when the user right clicks on the ToolBarTray, just like the books describe.
So, I tried to get rid of the Header by setting:
toolBar.HeaderTemplate = new DataTemplate();
This works, but now there's a small unsightly gap in the toolbar.
- Is there a way to make the header invisible without the gap?
- Why are the books clearly wrong? Did something change between then and now?