【问题标题】:LayoutDocument hide header tabs in DockingManager.DocumentPaneControlStyleLayoutDocument 隐藏 DockingManager.DocumentPaneControlStyle 中的标题选项卡
【发布时间】:2016-02-16 03:58:18
【问题描述】:

我正在使用 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>

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

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

TL;DR

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

【问题讨论】:

    标签: wpf xaml avalondock


    【解决方案1】:

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

    ControlTemplate 中似乎没有任何属性可以控制DocumentPaneTabPanelVisibility。 如果您检查用于LayoutDocumentPaneControl here 的默认Style 您可以看到没有TemplateBinding 或任何DataTrigger 影响名为DocumentPaneTabPanelHeaderPanel 所以我看不到更改它而不修改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 中,LayoutDocumentPane 上有一个ShowHeader 属性。所以在那个版本中你可以这样做:

    <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>
    

    【讨论】:

    • 非常感谢。刚刚安装了最新版本 10 分钟,然后你才知道自己发现了 ShowHeader 功能;)
    • 这里关于最新版本的小问题。最新版本是 Xceed Extended WPF Toolkit Plus 的一部分,不是吗?
    • 扩展 WPF 工具包 3.0.0 版本中的 Avalon 扩展坞也具有“ShowHeader”属性:wpftoolkit.codeplex.com
    猜你喜欢
    • 2012-10-19
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多