LayoutDocument 在 DockingManager.DocumentPaneControlStyle 中隐藏 header 个标签

LayoutDocument hide header tabs in DockingManager.DocumentPaneControlStyle

我正在使用 Avalondock 2,需要隐藏 LayoutDocument 的 TabItem。我知道 Avalondock 1.3 中有一个功能,但似乎在 2.0 中消失了。

我已经尝试更改 LayoutDocumentPaneControl 的模板,想知道是否可以在不完全重新设计模板的情况下更改单个 属性。这就是我想要实现的目标。

<xcad:DockingManager.DocumentPaneControlStyle>
    <Style TargetType="{x:Type xcad:LayoutDocumentPaneControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type xcad:LayoutDocumentPaneControl}">
                    <xcad:DocumentPaneTabPanel x:Name="HeaderPanel" IsItemsHost="true" Margin="2,2,2,0" KeyboardNavigation.TabIndex="1" Visibility="Collapsed"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Visibility" Value="Collapsed"/>
    </Style>
</xcad:DockingManager.DocumentPaneControlStyle>

那部分隐藏了我想要的 Header,但当然也隐藏了其他所有内容。

那么有没有办法用 BasedOn 或其他东西隐藏 DocumentPaneTabPanel

TL;DR

有没有办法在 Avalondock 2 中隐藏 DocumentPaneTabPanel

不幸的是,没有其他办法。我使用了在这里找到的 AvalonDock 2.0:https://avalondock.codeplex.com/

似乎没有任何 属性 公开控制 ControlTemplateDocumentPaneTabPanelVisibility。 如果您检查用于 LayoutDocumentPaneControl here 的默认值 Style,您可以看到没有 TemplateBinding 或任何影响 DocumentPaneTabPanelDataTrigger HeaderPanel 所以我看不到不修改 ControlTemplate.

就可以改变它的方法

您应该创建一个 DockingManagerStyles.xaml ResourceDictionary 并将其放在那里:

<xcad:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<xcad:ActivateCommandLayoutItemFromLayoutModelConverter x:Key="ActivateCommandLayoutItemFromLayoutModelConverter"/>

<Style x:Key="TablessDocumentPaneControlStyle" TargetType="{x:Type xcad:LayoutDocumentPaneControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type xcad:LayoutDocumentPaneControl}">
                <Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <!--Following border is required to catch mouse events-->
                    <Border Background="Transparent" Grid.RowSpan="2"/>
                    <Grid  Panel.ZIndex="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <xcad:DocumentPaneTabPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Visibility="Collapsed"/>
                        <xcad:DropDownButton x:Name="MenuDropDownButton" 
                                                Style="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}" 
                                                Focusable="False" Grid.Column="1">
                            <xcad:DropDownButton.DropDownContextMenu>
                                <xcad:ContextMenuEx
                                ItemsSource="{Binding Model.ChildrenSorted, RelativeSource={RelativeSource TemplatedParent}}">
                                    <xcad:ContextMenuEx.ItemContainerStyle>
                                        <Style TargetType="{x:Type xcad:MenuItemEx}" BasedOn="{StaticResource {x:Type MenuItem}}">
                                            <Setter Property="HeaderTemplate" Value="{Binding Path=Root.Manager.DocumentPaneMenuItemHeaderTemplate}"/>
                                            <Setter Property="HeaderTemplateSelector" Value="{Binding Path=Root.Manager.DocumentPaneMenuItemHeaderTemplateSelector}"/>
                                            <Setter Property="IconTemplate" Value="{Binding Path=Root.Manager.IconContentTemplate}"/>
                                            <Setter Property="IconTemplateSelector" Value="{Binding Path=Root.Manager.IconContentTemplateSelector}"/>
                                            <Setter Property="Command" Value="{Binding Path=., Converter={StaticResource ActivateCommandLayoutItemFromLayoutModelConverter}}"/>
                                        </Style>
                                    </xcad:ContextMenuEx.ItemContainerStyle>
                                </xcad:ContextMenuEx>
                            </xcad:DropDownButton.DropDownContextMenu>
                            <Image Source="/Xceed.Wpf.AvalonDock;component/Themes/Generic/Images/PinDocMenu.png"/>
                        </xcad:DropDownButton>
                    </Grid>
                    <Border x:Name="ContentPanel" 
                            VerticalAlignment="Stretch" 
                            HorizontalAlignment="Stretch"  
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" 
                            Grid.Column="0" 
                            KeyboardNavigation.DirectionalNavigation="Contained" 
                            Grid.Row="1"
                            KeyboardNavigation.TabIndex="2" 
                            KeyboardNavigation.TabNavigation="Cycle">
                        <ContentPresenter x:Name="PART_SelectedContentHost" 
                                        ContentSource="SelectedContent" 
                                        Margin="{TemplateBinding Padding}"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Model.ChildrenCount}" Value="0">
                        <Setter Property="Visibility" Value="Collapsed" TargetName="MenuDropDownButton" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"/>
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                <Setter Property="ToolTip" Value="{Binding ToolTip}"/>
            </Style>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemTemplate">
        <Setter.Value>
            <DataTemplate>
                <xcad:LayoutDocumentTabItem Model="{Binding}"/>
            </DataTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <xcad:LayoutDocumentControl Model="{Binding}"/>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

然后将其包含在 App.xamlMergedDictionaries 部分,以在您的应用程序中全局更改选项卡。

您应该可以像这样使用它:

<xcad:DockingManager DocumentPaneControlStyle="{StaticResource TablessDocumentPaneControlStyle}">
    <!-- Layout here -->
</xcad:DockingManager>

更新

latest version on NuGet 中有一个 ShowHeader 属性 在 LayoutDocumentPane 上。所以在那个版本中你可以这样做:

<xcad:DockingManager>
    <xcad:LayoutRoot>
        <xcad:LayoutPanel Orientation="Horizontal">
            <xcad:LayoutPanel Orientation="Vertical">
                <xcad:LayoutPanel Orientation="Horizontal">
                    <xcad:LayoutDocumentPaneGroup x:Name="leftDocumentGroup">
                        <xcad:LayoutDocumentPane ShowHeader="False">
                            <xcad:LayoutDocument Title="Left Doc"></xcad:LayoutDocument>
                        </xcad:LayoutDocumentPane>
                    </xcad:LayoutDocumentPaneGroup>
                    <xcad:LayoutDocumentPaneGroup x:Name="rightDocumentGroup">
                        <xcad:LayoutDocumentPane>
                            <xcad:LayoutDocument Title="Right Doc"></xcad:LayoutDocument>
                        </xcad:LayoutDocumentPane>
                    </xcad:LayoutDocumentPaneGroup>
                </xcad:LayoutPanel>
            </xcad:LayoutPanel>
        </xcad:LayoutPanel>
    </xcad:LayoutRoot>
</xcad:DockingManager>