如何拉伸/最大化 AvalonDock 文档窗格

发布于 2024-12-16 10:45:33 字数 2982 浏览 3 评论 0原文

我在 .NET 3.5 上使用 AvalonDock v 1.3。

我在设计时向 DockingManager 添加了两个文档窗格。第一个设置为可见,第二个设置为隐藏/折叠(请参阅下面的 Visibility="Collapsed")。

当我启动应用程序时,第二个文档窗格可见,这是预期的行为,但不幸的是,可见文档面板不会显示拉伸到主窗口的边缘,尽管 Horizo​​ntalAlignment 是设置为“拉伸”。我将如何使这个剪辑(或最大化)到允许区域的边缘?

这是我正在使用的 xaml:

   <ad:DockingManager x:Name="dockManager" Grid.Row="1">
        <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
            <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>                    
            </ad:DocumentPane>
            <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>
            </ad:DocumentPane>
        </ad:ResizingPanel>
    </ad:DockingManager>

谢谢, Dave

根据请求,以下是完整的 XAML:

    <Window x:Class="AvalonDockSampleProject.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
      Title="MainWindow" Height="421" Width="948">
    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="24"/>
    </Grid.RowDefinitions>
    <Menu>
        <MenuItem Header="File">
            <MenuItem Header="Create DockableContent" Click="CreateDockableContent"/>
             <MenuItem Header="Layout">
                <MenuItem Header="Save" Click="SaveLayout"/>
                <MenuItem Header="Restore" Click="RestoreLayout"/>                    
            </MenuItem>
            <MenuItem Header="Exit"/>
        </MenuItem>
    </Menu>
    <ad:DockingManager x:Name="dockManager" Grid.Row="1">
        <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
            <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
                <ad:DocumentContent Title="A!"/>
                <ad:DocumentContent Title="B!"/>                    
            </ad:DocumentPane>
            <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>
            </ad:DocumentPane>
           </ad:ResizingPanel>
        </ad:DockingManager>                  
        <StatusBar Grid.Row="2">
            <StatusBarItem Content="AvalonDock 1.3 Sample Project"/>
        </StatusBar>
    </Grid>
</Window>

I am using AvalonDock v 1.3 on .NET 3.5.

I have added two Document Panes at design time to a DockingManager. The first one is set to be visible and the second is hidden/collapsed (see Visibility="Collapsed" below).

When I launch the application, the second Document Pane is not visible, which is the intended behaviour but unfortunately, the visible document panel does not display stretched to the edges of the main window despite the fact that HorizontalAlignment is set to "Stretched". How would I go about making this clip(or maximise) to the edges of the allowed area?

This is the xaml that I am using:

   <ad:DockingManager x:Name="dockManager" Grid.Row="1">
        <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
            <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>                    
            </ad:DocumentPane>
            <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>
            </ad:DocumentPane>
        </ad:ResizingPanel>
    </ad:DockingManager>

Thanks,
Dave

As per request, here is the full XAML:

    <Window x:Class="AvalonDockSampleProject.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
      Title="MainWindow" Height="421" Width="948">
    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="24"/>
    </Grid.RowDefinitions>
    <Menu>
        <MenuItem Header="File">
            <MenuItem Header="Create DockableContent" Click="CreateDockableContent"/>
             <MenuItem Header="Layout">
                <MenuItem Header="Save" Click="SaveLayout"/>
                <MenuItem Header="Restore" Click="RestoreLayout"/>                    
            </MenuItem>
            <MenuItem Header="Exit"/>
        </MenuItem>
    </Menu>
    <ad:DockingManager x:Name="dockManager" Grid.Row="1">
        <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
            <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
                <ad:DocumentContent Title="A!"/>
                <ad:DocumentContent Title="B!"/>                    
            </ad:DocumentPane>
            <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
                <ad:DocumentContent Title="A"/>
                <ad:DocumentContent Title="B"/>
            </ad:DocumentPane>
           </ad:ResizingPanel>
        </ad:DockingManager>                  
        <StatusBar Grid.Row="2">
            <StatusBarItem Content="AvalonDock 1.3 Sample Project"/>
        </StatusBar>
    </Grid>
</Window>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫罗兰の梦幻 2024-12-23 10:45:33

你是对的,在 XAML 中定义 collapsedDocumentPane 似乎有问题,因为 AvalonDoc 将为它保留空间(它是选项卡标题或其他内容),完全忽略 Visibility= “崩溃”,所以我最终在代码中添加/删除了我的。所以:

首先,从 XAML 中删除您的 "collapsedDocumentPane" (我将其注释掉,以便稍后可以将其用作后面代码的引用):

<ad:DockingManager x:Name="dockManager" Grid.Row="1">
    <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
        <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
            <ad:DocumentContent Title="A"/>
            <ad:DocumentContent Title="B"/>                    
        </ad:DocumentPane>
        <!--<ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
            <ad:DocumentContent Title="A"/>
            <ad:DocumentContent Title="B"/>
        </ad:DocumentPane>-->
    </ad:ResizingPanel>
</ad:DockingManager>

并在后面的代码中重新创建该 xaml(在您中xaml.cs 文件):

private DockablePane _collapsedDocumentPane;

private DockablePane CollapsedDocumentPane
{
  get
  {
    if (_collapsedDocumentPane== null)
    {
        _collapsedDocumentPane= new DockablePane();
        var a = new DockableContent
        {
           Title = "A",
           DataContext = _youViewModel, //if you pass data context
           DockableStyle = DockableStyle.AutoHide,
           Content = new RadGridView(), //just a sample control
         };
         var b = new DockableContent { Title = "B"};

        _collapsedDocumentPane.Items.Add(a);
        _collapsedDocumentPane.Items.Add(b);
     }
     return _errorsDockablePane;
   }
 }

然后是添加或删除它的方法:

private void EvaluateCollapsedDocPaneVisibility()
{
   //don't know your scenario
   if (NeedToDisplay_CollapsedDocPane)
   {
       if (!resizePanel.Children.Contains(CollapsedDocumentPane))
         resizePanel.Children.Add(CollapsedDocumentPane);
   }
   else
   {
       if (resizePanel.Children.Contains(CollapsedDocumentPane))
         resizePanel.Children.Remove(CollapsedDocumentPane);
   }
 }

注意,该属性是延迟加载的 - 仅在需要时构造。
所以现在你要做的就是在需要添加或删除时调用上面的方法。
这只是一个示例,您可以向方法添加一个参数来告诉它要做什么,或者其他什么,希望这可以帮助/让您继续前进。

You are right, it seems problematic to define your collapsedDocumentPane in XAML, as AvalonDoc will reserve the space for it (it's tab header or whatever) completely disregarding Visibility="Collapsed", so I ended up adding/removinhg mine in code. So:

First, remove your "collapsedDocumentPane" from XAML (I am commenting it out, so that it can be used as a reference from code behind later):

<ad:DockingManager x:Name="dockManager" Grid.Row="1">
    <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal">
        <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" >
            <ad:DocumentContent Title="A"/>
            <ad:DocumentContent Title="B"/>                    
        </ad:DocumentPane>
        <!--<ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed">
            <ad:DocumentContent Title="A"/>
            <ad:DocumentContent Title="B"/>
        </ad:DocumentPane>-->
    </ad:ResizingPanel>
</ad:DockingManager>

And recreated that xaml in code behind (in you xaml.cs file):

private DockablePane _collapsedDocumentPane;

private DockablePane CollapsedDocumentPane
{
  get
  {
    if (_collapsedDocumentPane== null)
    {
        _collapsedDocumentPane= new DockablePane();
        var a = new DockableContent
        {
           Title = "A",
           DataContext = _youViewModel, //if you pass data context
           DockableStyle = DockableStyle.AutoHide,
           Content = new RadGridView(), //just a sample control
         };
         var b = new DockableContent { Title = "B"};

        _collapsedDocumentPane.Items.Add(a);
        _collapsedDocumentPane.Items.Add(b);
     }
     return _errorsDockablePane;
   }
 }

Then a method that adds or removes it:

private void EvaluateCollapsedDocPaneVisibility()
{
   //don't know your scenario
   if (NeedToDisplay_CollapsedDocPane)
   {
       if (!resizePanel.Children.Contains(CollapsedDocumentPane))
         resizePanel.Children.Add(CollapsedDocumentPane);
   }
   else
   {
       if (resizePanel.Children.Contains(CollapsedDocumentPane))
         resizePanel.Children.Remove(CollapsedDocumentPane);
   }
 }

Note, the property is lazy loaded - constructed only when needed.
So now all you gotta do is call the method above whenever you need to add or remove.
This is just a sample, you can add an arg to the method to tell it what to do, or whatever, hope this helps/gets you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文