Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WPF中,如何使ToolBar.Header消失?_Wpf_Toolbar - Fatal编程技术网

在WPF中,如何使ToolBar.Header消失?

在WPF中,如何使ToolBar.Header消失?,wpf,toolbar,Wpf,Toolbar,我在两本不同的书中读到,在WPF中,ToolBar.Header属性没有任何作用: 由Adam Nathan,PG 119释放的Windows演示文稿基金会 但是,我正在动态创建工具栏对象,就像这个tbtToolBar实际上是Xaml中定义的工具栏托盘,vm是窗口的ViewModel: foreach (IToolBarViewModel toolBarViewModel in vm.ToolBars) { ToolBar toolBar = new ToolBar(); too

我在两本不同的书中读到,在WPF中,ToolBar.Header属性没有任何作用:

由Adam Nathan,PG 119释放的Windows演示文稿基金会 但是,我正在动态创建工具栏对象,就像这个tbtToolBar实际上是Xaml中定义的工具栏托盘,vm是窗口的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);
}
标题属性作为工具栏中的第一项清楚地显示在标签中。这不是我想要的行为。我想在用户右键单击工具栏托盘时,将标题用作工具栏下拉列表中的标题,就像书中描述的那样

因此,我试图通过设置以下内容来删除标题:

toolBar.HeaderTemplate = new DataTemplate();
这是可行的,但现在工具栏上有一个小的难看的间隙

有没有办法使标题在没有间隙的情况下不可见? 为什么这些书显然是错的?从那时到现在有什么变化吗?
我唯一能做到这一点的方法是保持Header属性为null,并在ToolBarViewModel上创建另一个名为Name的属性