AvalonDock - 防止文档窗格中的可锚定窗格停靠

本文关键字:停靠 文档 AvalonDock | 更新日期: 2023-09-27 18:19:02

是否可以防止可定位对象停靠到我的文档窗格中?我希望它们可以拖动并在屏幕上移动,但有时用户将它们拖到文档窗格中,这使它们看起来很差。然后他们关闭选项卡,我无法重新打开可定位对象。

如果它有帮助,我的阿瓦隆代码如下:

        <avalonDock:DockingManager.Theme>
            <avalonDock:VS2010Theme />
        </avalonDock:DockingManager.Theme>
        <avalonDock:DockingManager.DocumentHeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <StackPanel Orientation="Horizontal">
                        <!-- the TextBlock named Limiter is used to limit the height of the TextBlock for the workflow name. -->
                        <TextBlock x:Name="Limiter" TextWrapping="NoWrap" Visibility="Hidden"
                                                       TextTrimming="CharacterEllipsis">
                                                L
                        </TextBlock>
                        <TextBlock Text="{Binding Path=Title}" VerticalAlignment="Center"
                                   ToolTip="{StaticResource WorkflowTabItemToolTip}"
                                   MaxHeight="{Binding ActualHeight, ElementName=Limiter}" MaxWidth="150"
                                   TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Margin="0,0,2,0" 
                                   AutomationProperties.AutomationId="WorkflowTabTitleText"/>
                        <TextBlock Text=" *" 
                                   ToolTip="Has unsaved changes"
                                   Visibility="{Binding Content.UnsavedEdits, Converter={StaticResource BoolToVis}}"
                                   AutomationProperties.AutomationId="DirtyTabIndicator"/>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </avalonDock:DockingManager.DocumentHeaderTemplate>
        <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
            <utilities1:PanesStyleSelector>
                <utilities1:PanesStyleSelector.WebUIStyle>
                    <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
                        <Setter Property="Title" Value="{Binding Model.Title}"/>
                        <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                        <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                        <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                        <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                        <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                    </Style>
                </utilities1:PanesStyleSelector.WebUIStyle>
                <utilities1:PanesStyleSelector.DocumentStyle>
                    <Style TargetType="{x:Type avalonDock:LayoutItem}">
                        <Setter Property="Title" Value="{Binding Model.WorkflowName}" />
                        <Setter Property="IsActive" Value="{Binding Model.IsActive}" />
                        <Setter Property="IsSelected" Value="{Binding Model.IsActive}" />
                    </Style>
                </utilities1:PanesStyleSelector.DocumentStyle>
            </utilities1:PanesStyleSelector>
        </avalonDock:DockingManager.LayoutItemContainerStyleSelector>
        <avalonDock:DockingManager.LayoutItemTemplateSelector>
            <utilities1:PanesTemplateSelector>
                <utilities1:PanesTemplateSelector.WorkflowDesignerViewTemplate>
                    <DataTemplate>
                        <ContentControl cal:View.Model="{Binding}" IsTabStop="False" />
                    </DataTemplate>
                </utilities1:PanesTemplateSelector.WorkflowDesignerViewTemplate>
                <utilities1:PanesTemplateSelector.WebUIViewTemplate>
                    <DataTemplate>
                        <ContentControl cal:View.Model="{Binding}" IsTabStop="False" />
                    </DataTemplate>
                </utilities1:PanesTemplateSelector.WebUIViewTemplate>
            </utilities1:PanesTemplateSelector> 
        </avalonDock:DockingManager.LayoutItemTemplateSelector>
        <avalonDock:LayoutRoot>
            <avalonDock:LayoutPanel Orientation="Horizontal">
                <avalonDock:LayoutDocumentPaneGroup>
                    <avalonDock:LayoutDocumentPane AutomationProperties.AutomationId="AvalonDocumentPane"/>
                </avalonDock:LayoutDocumentPaneGroup>
                <avalonDock:LayoutAnchorablePane DockWidth="800" DockMinWidth="400" AutomationProperties.AutomationId="WebUIPane"/>
                <avalonDock:LayoutAnchorablePane DockWidth="225" DockMinWidth="225" AutomationProperties.AutomationId="ActivitiesPane">
                    <avalonDock:LayoutAnchorable Title="Activities" AutoHideWidth="225" AutoHideMinWidth="225" CanClose="False" CanHide="False">
                        <toolbox:ToolboxControl Name="Toolbox" AutomationProperties.AutomationId="ActivitiesToolbox"
                                                        utilities1:ToolboxItemSource.ToolboxItems="{Binding ToolboxList}" />
                    </avalonDock:LayoutAnchorable>
                </avalonDock:LayoutAnchorablePane>
            </avalonDock:LayoutPanel>
        </avalonDock:LayoutRoot>
    </avalonDock:DockingManager>

AvalonDock - 防止文档窗格中的可锚定窗格停靠

虽然我没有找到防止停靠的直接方法,但我能够解决基本问题,即为工具窗口和文档窗口自定义不同的选项卡标题。我的文档窗口在选项卡标题中显示星号 (*( 以指示更改(就像 VS 一样(,而工具窗口不应这样做。

解决方案是使用 DocumentHeaderTemplateSelector 并为其提供两个不同的模板,文档和工具窗口各一个。下面是 XAML:

<xcad:DockingManager.DocumentHeaderTemplateSelector>
  <bd:DocumentHeaderTemplateSelector>
    <bd:DocumentHeaderTemplateSelector.DocumentTemplate>
      <DataTemplate>
        <StackPanel Orientation="Horizontal">
          <Image Source="Resources'AppIcon.ico" Margin="0,0,4,0" Width="16" />
          <TextBlock Text="{Binding Title}" />
          <TextBlock Text=" *" Visibility="{Binding Content.IsDirty, Converter={StaticResource BoolToVisibilityConverter}}" />
        </StackPanel>
      </DataTemplate>
    </bd:DocumentHeaderTemplateSelector.DocumentTemplate>
    <bd:DocumentHeaderTemplateSelector.ToolWindowTemplate>
      <DataTemplate>
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="{Binding Title}" />
        </StackPanel>
      </DataTemplate>
    </bd:DocumentHeaderTemplateSelector.ToolWindowTemplate>
  </bd:DocumentHeaderTemplateSelector>
</xcad:DockingManager.DocumentHeaderTemplateSelector>

选择器类很简单:

Public Class DocumentHeaderTemplateSelector
  Inherits DataTemplateSelector
  Public Property DocumentTemplate As DataTemplate
  Public Property ToolWindowTemplate As DataTemplate
  Public Overrides Function SelectTemplate(item As Object, container As System.Windows.DependencyObject) As System.Windows.DataTemplate
    Dim itemAsLayoutContent = TryCast(item, Xceed.Wpf.AvalonDock.Layout.LayoutContent)
    If TypeOf item Is Xceed.Wpf.AvalonDock.Layout.LayoutDocument AndAlso TypeOf DirectCast(item, Xceed.Wpf.AvalonDock.Layout.LayoutDocument).Content Is DocumentVM Then
      Return DocumentTemplate
    Else
      Return ToolWindowTemplate
    End If
  End Function
End Class

现在,我的工具窗口不显示星号 (*( 和图标,即使它们被移动到文档窗格中也是如此。

希望这对未来的某人有所帮助。

    <avalonDock:LayoutRoot>
                <avalonDock:LayoutPanel CanRepositionItems="False" Orientation="Vertical">
                    <avalonDock:LayoutAnchorablePane Name="ToolsPane" DockHeight="100" CanRepositionItems="False">
                        <avalonDock:LayoutAnchorable CanDockAsTabbedDocument="False"/>
                    </avalonDock:LayoutAnchorablePane>
                    
                </avalonDock:LayoutPanel>
                
</avalonDock:LayoutRoot>

avalonDock:LayoutAnchorable set 中

CanDockAsTabbedDocument

属性为。这将禁用可锚定视图以停靠在文档窗格中。