xcteed中AnchorablePaneTabPanel的用法
时间: 2023-07-08 08:04:25 浏览: 51
AnchorablePaneTabPanel 是 Xceed.Wpf.AvalonDock 控件库中的一个控件,用于在 DockingManager 中显示 AnchorablePane 的标签页。
使用 AnchorablePaneTabPanel 的步骤如下:
1. 将 AnchorablePaneTabPanel 添加到 DockingManager 的 AnchorablePaneStyle 属性中:
```xml
<xcad:DockingManager>
<xcad:DockingManager.AnchorablePaneStyle>
<Style TargetType="{x:Type xcad:AnchorablePane}">
<Setter Property="Title" Value="{Binding Model.Title}" />
<Setter Property="xcad:DockingManager.ShowHeader" Value="True" />
<Setter Property="xcad:DockingManager.ShowCloseButton" Value="True" />
<Setter Property="xcad:DockingManager.ShowMaximizeButton" Value="False" />
<Setter Property="xcad:DockingManager.ShowMinimizeButton" Value="False" />
<Setter Property="xcad:DockingManager.IconSource" Value="{Binding Model.IconSource}" />
<Setter Property="xcad:DockingManager.ControlStyle">
<Setter.Value>
<Style TargetType="{x:Type xcad:LayoutAnchorableControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type xcad:LayoutAnchorableControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<xcad:AnchorablePaneTabPanel Grid.Row="0" />
<ContentPresenter Grid.Row="1"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</xcad:DockingManager.AnchorablePaneStyle>
</xcad:DockingManager>
```
2. 在 AnchorablePane 中添加 AnchorableContent,并设置 Title 和 Content 属性:
```xml
<xcad:DockingManager>
...
<xcad:LayoutRoot>
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePane DockWidth="200">
<xcad:LayoutAnchorable>
<xcad:LayoutAnchorable.Title>
<TextBlock Text="My Anchorable" />
</xcad:LayoutAnchorable.Title>
<xcad:LayoutAnchorable.Content>
<TextBlock Text="I am an Anchorable." />
</xcad:LayoutAnchorable.Content>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
...
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
```
3. 在 AnchorablePaneTabPanel 中使用模板绑定来设置 TabItem 的样式:
```xml
<xcad:AnchorablePaneTabPanel>
<xcad:AnchorablePaneTabPanel.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border x:Name="Border"
BorderThickness="1,1,1,0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Margin="0,0,-4,0">
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="12,2,12,2"
RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource ActiveTabBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource ActiveTabForegroundBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource HoverTabBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource HoverTabForegroundBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background" Value="{StaticResource HoverTabBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource HoverTabForegroundBrush}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</xcad:AnchorablePaneTabPanel.ItemContainerStyle>
</xcad:AnchorablePaneTabPanel>
```
其中,ActiveTabBackgroundBrush、ActiveTabForegroundBrush、HoverTabBackgroundBrush、HoverTabForegroundBrush 是自定义的 Brush,用于设置不同状态下 TabItem 的背景和前景色。