AvalonDock DocumentHeaderTemplate 不适用于浮动 Windows

AvalonDock DocumentHeaderTemplate not working for Floating Windows

在 AvalonDock 中,我们使用 LayoutDocumentExtended 在标题中添加一些 AdditionalInformation(不仅仅是我们项目中的字符串)。

在此测试代码中,我们将 DocumentHeaderTemplate 设置如下。

   <xcad:DockingManager.DocumentHeaderTemplate>
    <DataTemplate DataType="{x:Type local:LayoutDocumentExtended}">
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Title, StringFormat={}{0} ---- }" />
        <TextBlock Text="{Binding AdditionalString}" />
      </StackPanel>
    </DataTemplate>
  </xcad:DockingManager.DocumentHeaderTemplate>
    <xcad:LayoutRoot>
      <xcad:LayoutPanel Orientation="Vertical" >
        <xcad:LayoutDocumentPane>
          <xcad:LayoutDocumentPane.Children>
            <local:LayoutDocumentExtended Title="Test1" AdditionalString="848451">  </local:LayoutDocumentExtended>
            <local:LayoutDocumentExtended Title="Test2" AdditionalString="1"></local:LayoutDocumentExtended>
          </xcad:LayoutDocumentPane.Children>
        </xcad:LayoutDocumentPane>
    </xcad:LayoutPanel>
  </xcad:LayoutRoot>

如果我将 LayoutDocument 取消停靠为 FloatingWindow,则只会显示 Title 而不会显示 AdditionalString。一旦我再次重新停靠它,AdditionalString 就会再次显示。有人知道如何在 FloatingWindows 上设置可配置的 DocumentHeaderTemplate 吗?

LayoutDocumentFloatingWindowControl控件使用WindowChrome定义标题栏。您可能想修改 chrome 的标题栏以允许它显示额外的垂直内容,即额外的行。或者,考虑在括号中和同一行中显示额外信息。

覆盖 DocumentTitleTemplate 以布局标题:

<DataTemplate x:Key="DocumentTitleTemplate">
  <TextBlock Text="{Binding Title}"
             TextTrimming="CharacterEllipsis">
  </TextBlock>
</DataTemplate>

覆盖LayoutDocumentFloatingWindowControl样式修改标题栏高度:

  <Style x:Key="{x:Type avalonDockControls:LayoutDocumentFloatingWindowControl}"
         TargetType="{x:Type avalonDockControls:LayoutDocumentFloatingWindowControl}">
    <Setter Property="Background"
            Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
    <Setter Property="BorderBrush"
            Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
    <Setter Property="BorderThickness"
            Value="3" />
    <Setter Property="shell:WindowChrome.WindowChrome">
      <Setter.Value>
        <shell:WindowChrome ResizeBorderThickness="10"
                            CaptionHeight="16"
                            CornerRadius="3,3,3,3"
                            GlassFrameThickness="0"
                            ShowSystemMenu="False" />
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type avalonDockControls:LayoutDocumentFloatingWindowControl}">
          <AdornerDecorator>
            <Grid>
              <Border x:Name="WindowBorder"
                      BorderThickness="{TemplateBinding BorderThickness}"
                      Background="{TemplateBinding Background}"
                      BorderBrush="{TemplateBinding BorderBrush}">
                <Grid Margin="3">
                  <Grid.RowDefinitions>
                    <RowDefinition MinHeight="16"
                                   Height="Auto" />
                    <RowDefinition Height="*" />
                  </Grid.RowDefinitions>
                  <Grid UseLayoutRounding="True">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*" />
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter Content="{Binding Model.RootDocument, RelativeSource={RelativeSource TemplatedParent}}"
                                      ContentTemplate="{Binding Model.Root.Manager.DocumentTitleTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                      ContentTemplateSelector="{Binding Model.Root.Manager.DocumentTitleTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" />


                    <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                            Focusable="False"
                            Visibility="{Binding IsMaximized, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolToVisibilityConverter}}"
                            Style="{DynamicResource {x:Static ToolBar.ButtonStyleKey}}"
                            Command="{x:Static shell:SystemCommands.MaximizeWindowCommand}"
                            CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            ToolTip="{x:Static avalonDockProperties:Resources.Window_Maximize}"
                            Grid.Column="2">
                      <Image Source="{xctk:ImageUri AssemblyName=Xceed.Wpf.AvalonDock, Path=Themes/Generic/Images/PinMaximize.png}">
                      </Image>
                    </Button>

                    <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                            Focusable="False"
                            Visibility="{Binding IsMaximized, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}"
                            Style="{DynamicResource {x:Static ToolBar.ButtonStyleKey}}"
                            Command="{x:Static shell:SystemCommands.RestoreWindowCommand}"
                            CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            ToolTip="{x:Static avalonDockProperties:Resources.Window_Restore}"
                            Grid.Column="2">
                      <Image Source="{xctk:ImageUri AssemblyName=Xceed.Wpf.AvalonDock, Path=Themes/Generic/Images/PinRestore.png}">
                      </Image>
                    </Button>

                    <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                            Focusable="False"
                            Style="{DynamicResource {x:Static ToolBar.ButtonStyleKey}}"
                            Command="{Binding Path=RootDocumentLayoutItem.CloseCommand, RelativeSource={RelativeSource TemplatedParent}}"
                            ToolTip="{x:Static avalonDockProperties:Resources.Document_Close}"
                            Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
                            Grid.Column="3">
                      <Image Source="{xctk:ImageUri AssemblyName=Xceed.Wpf.AvalonDock, Path=Themes/Generic/Images/PinClose.png}">
                      </Image>
                    </Button>
                  </Grid>
                  <ContentPresenter Content="{TemplateBinding Content}"
                                    Grid.Row="1" />
                </Grid>
              </Border>
            </Grid>
          </AdornerDecorator>
          <ControlTemplate.Triggers>
            <Trigger Property="WindowState"
                     Value="Maximized">
              <Setter Property="Padding"
                      Value="3"
                      TargetName="WindowBorder" />
            </Trigger>
            <DataTrigger Binding="{Binding Model.RootDocument.IsActive, RelativeSource={RelativeSource Self}}"
                         Value="True">
              <Setter TargetName="WindowBorder"
                      Property="BorderBrush"
                      Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>