首页 > 解决方案 > AvolonDock 查找所有布局

问题描述

我试图弄清楚如何使用 AvalonDock。我不仅限于 MVVM,而且很高兴使用代码隐藏 WPF 进行以下工作。

我有以下方法,它打开一个新的 AvalonDockLayoutDocument并向其添加 WPF 用户控件。

在打开一个新LayoutDocument的 之前,方法会检查新的标题 LayoutDocument是否已经存在于LayoutDocumentPane.

这似乎运作良好。

问题是,如果LayoutDocument被打开的已经存在并且已经被取消锚定,LayoutDocumentPane那么它就不再存在于 LayoutDocumentPane.

LayoutDocument无论它们锚定在哪里,我如何搜索所有内容?

方法如下:

private void OpenWindow(string title, System.Windows.Controls.UserControl userControl)
    {
        var firstDocumentPane = dockManager.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
        if (firstDocumentPane != null)
        {
            bool addChild = true;
            foreach (LayoutDocument child in LayoutDocumentPane.Children)
            {
                if (child.Title == title)
                {
                    child.IsSelected = true;
                    addChild = false;
                }
            }
            if (addChild == true)
            {
                LayoutDocument doc = new LayoutDocument();
                doc.Title = title;
                doc.Content = userControl;
                doc.IsSelected = true;
                firstDocumentPane.Children.Add(doc);
            }
        }
    }

标签: c#wpfavalondock

解决方案


我已经想通了。

下面将列出所有LayoutDocument文件dockManager

var currentContentsList = dockManager.Layout.Descendents().OfType<LayoutDocument>().ToArray();

然后循环如下:

foreach (LayoutDocument child in currentContentsList)
        {
             child.IsActive = true;
        }

推荐阅读