【问题标题】:AvalonDock Layout Without DocumentPane没有 DocumentPane 的 AvalonDock 布局
【发布时间】:2016-04-13 14:44:29
【问题描述】:

我正在尝试使用 avalon dock 创建一个布局,看起来像这样:

在左侧,用户应该选择红色框中显示的内容。如果将中间的红色框声明为文档窗格,并将内容显示为选项卡,则可以轻松实现这种布局。 但是,在这种情况下不需要使用选项卡,因为只有一个内容,所以我想将红色框显示为可锚定而不是文档。 所以,基本上,我想要一个完全不包含文档窗格的布局。 到目前为止,这是我的代码:

<ad:DockingManager               
    LayoutUpdateStrategy="{StaticResource dockingLayoutStrategy}" 
        AnchorablesSource="{Binding Path=Anchorables}" 
        ActiveContent="{Binding Path=ActiveContent, Mode=TwoWay}"
       >
<ad:DockingManager.LayoutItemContainerStyleSelector>
    <local:DockingPaneStyleSelector>
        <local:DockingPaneStyleSelector.AnchorableStyle>
            <Style TargetType="{x:Type adc:LayoutAnchorableItem}">
                <!-- a bunch of properties-->
            </Style>
        </local:DockingPaneStyleSelector.AnchorableStyle>
        <local:DockingPaneStyleSelector.PaneStyle>
            <!-- a bunch of properties-->
        </local:DockingPaneStyleSelector.PaneStyle>
    </local:DockingPaneStyleSelector>
</ad:DockingManager.LayoutItemContainerStyleSelector>

<adl:LayoutRoot>
    <adl:LayoutPanel Orientation="Horizontal">
        <adl:LayoutAnchorablePane  Name="ContentSelectionPane" DockWidth="100"/>
        <adl:LayoutPanel Orientation="Vertical" DockWidth="*" IsMaximized="True">
            <adl:LayoutPanel Orientation="Horizontal">
                <adl:LayoutAnchorablePane Name="MainPane" IsMaximized="True" />
                <adl:LayoutAnchorablePane Name="PropertyPane" DockWidth="300"/>
            </adl:LayoutPanel>

            <adl:LayoutAnchorablePane Name="StuffPane" DockHeight="150"/>
        </adl:LayoutPanel>
    </adl:LayoutPanel>
</adl:LayoutRoot>

我遇到的第一个问题是,当加载左侧窗格时,它会占用所有可用空间,并且永远不允许显示右侧。如果我注释掉左侧窗格,则会显示窗口的右侧。

第二个问题是窗格现在确实具有我声明的大小,但总是占用可用大小的一半。例如。如果我有:

    <adl:LayoutRoot>
    <adl:LayoutPanel Orientation="Horizontal">
        <adl:LayoutAnchorablePane  Name="ContentSelectionPane" DockWidth="100"/>
        <adl:LayoutAnchorablePane Name="{x:Static si:Panes.DocumentPane}" DockWidth="*" IsMaximized="True" />
    </adl:LayoutPanel>
</adl:LayoutRoot>

两个窗格正好占可用位置的一半。

关于如何实现不显示选项卡但可访问的“DocumentPane”大小行为的任何想法?

【问题讨论】:

  • 过去 2 小时我也在寻找这个答案...
  • 有什么想法吗?到目前为止,您尝试过什么?

标签: wpf avalondock


【解决方案1】:

嗯,我做了一个对我有用的重大“破解”。我在包含文档窗格的容器顶部设置了一个负上边距。负边距将内容拉起,很好地隐藏了文档选项卡。

这很棘手,因为您必须在内容呈现/加载后执行此操作,因为 Xaml 窗格并不是放入可视树的实际视觉对象。

这是我用于文档区域的 Xaml:

<xcad:LayoutDocumentPane
    x:Name="LayoutDocumentPaneArea"
    CanRepositionItems="False"
    DockMinHeight="0"
    DockMinWidth="0"
    IsMaximized="True">
    <xcad:LayoutDocument
        CanClose="False"
        CanFloat="False"
        IsMaximized="True">
        <Grid x:Name="DocumentArea" />
    </xcad:LayoutDocument>
</xcad:LayoutDocumentPane>

然后在窗口的 Content_Rendered 事件中调用此函数以剥离文档选项卡,在我的例子中,我在那里托管的内容的 1px 边框:

private void TrimDocumentArea()
{
    var border = DocumentArea.FindVisualAncestor<Border>();
    if (border != null)
    {
        border = border.FindVisualAncestor<Border>();
        if (border != null && border.Name == "ContentPanel")
        {
            border.Margin = new Thickness(-1, -21, -1, -1);
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多