I'm using Avalondock 2 and need to hide the TabItem of a LayoutDocument
. I know that there was a function back in Avalondock 1.3 which seems to be gone in 2.0.
I've tried to change the template of the LayoutDocumentPaneControl
and want to know if it's possible to change a single Property without a complete redesign of the template. Here's what I i want to achive.
<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>
That part hides the Header as I want, but of course everything else too.
So is there a way to hide the DocumentPaneTabPanel
with a BasedOn
or something?
TL;DR
Is there a way to hide the DocumentPaneTabPanel
in Avalondock 2?
There is no other way unfortunately. I used the AvalonDock 2.0 found here: https://avalondock.codeplex.com/
There doesn't seem to be any property exposed to control the Visibility
of the DocumentPaneTabPanel
in the ControlTemplate
.
If you check the default Style
used for the LayoutDocumentPaneControl
here you can see that there is no TemplateBinding
or any DataTrigger
affecting the DocumentPaneTabPanel
named HeaderPanel
so I don't see a way of changing it without modifying the ControlTemplate.
You should create a DockingManagerStyles.xaml
ResourceDictionary
and put this in there:
<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>
Then include it in the MergedDictionaries
section of your App.xaml
to change the tabs globally in your application.
You should be able to use it like:
<xcad:DockingManager DocumentPaneControlStyle="{StaticResource TablessDocumentPaneControlStyle}">
<!-- Layout here -->
</xcad:DockingManager>
Update
In the latest version on NuGet there is a ShowHeader
property on LayoutDocumentPane
. So in that version you can just do:
<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>