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:

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


1 answer


The only way I was able to make this work was to keep the title property null and create another property in the ToolBarViewModel called Name.



0


a source







All Articles