AvalonDock - 如何禁用所有锚点的自动隐藏功能

AvalonDock - How to disable autohide capability for all anchorables

我希望从我对 AvalonDock 的使用中删除 "AutoHide" 功能。我在此示例之后为我的解决方案建模:http://lostindetails.com/blog/post/AvalonDock-2.0-with-MVVM

我目前的想法是,如果我可以从选项卡("closing X" 旁边的符号)和上下文菜单中删除选项,用户将无法执行隐藏操作。如果还有其他方法可以完成隐藏操作的删除,那也可以。

从选项卡和上下文菜单中删除隐藏

在示例中,他能够在 LayoutItem 上设置 CanClose 属性,从而影响由于位于 DocumentsSource 内而显示的任何项目.我想做同样的事情,但是对于 CanHideCanAutoHide 并让它影响我的 AnchorablesSource.

中的 Anchorables

编辑:我添加了以下行:

<Setter Property="dockctrl:LayoutAnchorableItem.CanHide" Value="False" />

现在让我完成了一半。此行删除了隐藏功能,但它不会删除 "AutoHide" 引脚符号(或上下文菜单选项)。我知道 CanAutoHide 属性 确实存在,我只是不确定如何设置它。下面是相关的 docs from Xceed

当前解决方案

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>


        <dock:DockingManager x:Name="AvalonDockDockingManager" Grid.Row="1"
                    AllowMixedOrientation="True"
                    DataContext="{Binding DockManagerViewModel}"
                    DocumentsSource="{Binding Documents}"
                    AnchorablesSource="{Binding Anchorables}" >

            <dock:DockingManager.Resources>
            </dock:DockingManager.Resources>

            <dock:DockingManager.LayoutItemContainerStyle>
                <Style TargetType="{x:Type dockctrl:LayoutItem}" >
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                    <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
                    <Setter Property="CanClose"  Value="{Binding Model.CanClose}" />
                    <Setter Property="dockctrl:LayoutAnchorableItem.CanHide" Value="False" />


                </Style>
            </dock:DockingManager.LayoutItemContainerStyle>



            <dock:DockingManager.AnchorablePaneControlStyle>
                <Style TargetType="{x:Type dockctrl:LayoutAnchorableItem}" >
                    <Setter Property="CanHide"  Value="False" />
                </Style>
            </dock:DockingManager.AnchorablePaneControlStyle>



        </dock:DockingManager>
    </Grid>
  1. 您将不得不 re-style AvalonDock 的某些元素以摆脱自动隐藏引脚。下面是取自 Generic.xaml.

  2. AchorablePaneTitle 样式的示例 XAML
  3. 作为替代解决方案:您还可以通过在 this sample application 中设置 CanAutoHide="False" and CanHide="False" 让 Pin 图消失。

改变后的 XAML 看起来像这样

<avalonDock:LayoutAnchorable x:Name="WinFormsWindow"
                             ContentId="WinFormsWindow"
                             Title="WinForms Window"
                             ToolTip="My WinForms Tool"
                             CanAutoHide="False"
                             CanHide="False"
                             CanClose="False" >
    <winformsIntegration:WindowsFormsHost x:Name="winFormsHost" Background="White"/>
</avalonDock:LayoutAnchorable>

这是从上面链接的示例应用程序截取的屏幕截图。请注意 Winforms Window 上缺少的引脚。

覆盖 AnchorablePaneTitle 样式以摆脱 PART_AutoHidePin 中定义的图钉(例如:在其上设置 Visibility = "Collapsed")。

  <Style TargetType="avalonDockControls:AnchorablePaneTitle">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate>
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>
              <avalonDockControls:DropDownControlArea DropDownContextMenu="{Binding Model.Root.Manager.AnchorableContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                                      DropDownContextMenuDataContext="{Binding Path=LayoutItem, RelativeSource={RelativeSource TemplatedParent}}">
                <ContentPresenter Content="{Binding Model, RelativeSource={RelativeSource TemplatedParent}}"
                                  ContentTemplate="{Binding Model.Root.Manager.AnchorableTitleTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                  ContentTemplateSelector="{Binding Model.Root.Manager.AnchorableTitleTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" />
              </avalonDockControls:DropDownControlArea>

              <avalonDockControls:DropDownButton Style="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}"
                                                 Focusable="False"
                                                 Grid.Column="1"
                                                 DropDownContextMenu="{Binding Model.Root.Manager.AnchorableContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                                 DropDownContextMenuDataContext="{Binding Path=LayoutItem, RelativeSource={RelativeSource TemplatedParent}}"
                                                 ToolTip="{x:Static avalonDockProperties:Resources.Anchorable_CxMenu_Hint}">
                <Border Background="White">
                  <Image Source="/Xceed.Wpf.AvalonDock;component/Themes/Generic/Images/PinMenu.png">
                  </Image>
                </Border>
              </avalonDockControls:DropDownButton>

              <Button x:Name="PART_AutoHidePin"
                      Grid.Column="2"
                      Focusable="False"
                      Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                      Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
                      Command="{Binding Path=LayoutItem.AutoHideCommand, RelativeSource={RelativeSource TemplatedParent}}"
                      ToolTip="{x:Static avalonDockProperties:Resources.Anchorable_BtnAutoHide_Hint}">
                <Border Background="White">
                  <Image Source="/Xceed.Wpf.AvalonDock;component/Themes/Generic/Images/PinAutoHide.png">
                  </Image>
                </Border>
              </Button>

              <Button x:Name="PART_HidePin"
                      Grid.Column="3"
                      Focusable="False"
                      Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                      Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
                      Command="{Binding Path=LayoutItem.HideCommand, RelativeSource={RelativeSource TemplatedParent}}"
                      ToolTip="{x:Static avalonDockProperties:Resources.Anchorable_BtnClose_Hint}">
                <Border Background="White">
                  <Image Source="/Xceed.Wpf.AvalonDock;component/Themes/Generic/Images/PinClose.png">
                  </Image>
                </Border>
              </Button>


            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding Model.IsAutoHidden, RelativeSource={RelativeSource Mode=Self}}"
                         Value="True">
              <Setter Property="LayoutTransform"
                      TargetName="PART_AutoHidePin">
                <Setter.Value>
                  <RotateTransform Angle="90" />
                </Setter.Value>
              </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding Model.CanClose, RelativeSource={RelativeSource Mode=Self}}"
                         Value="True">
              <Setter Property="Command"
                      TargetName="PART_HidePin"
                      Value="{Binding Path=LayoutItem.CloseCommand, RelativeSource={RelativeSource TemplatedParent}}" />
              <Setter Property="ToolTip"
                      TargetName="PART_HidePin"
                      Value="{x:Static avalonDockProperties:Resources.Document_Close}" />

            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>