c# - 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);
}
}
}
解决方案
我已经想通了。
下面将列出所有LayoutDocument
文件dockManager
var currentContentsList = dockManager.Layout.Descendents().OfType<LayoutDocument>().ToArray();
然后循环如下:
foreach (LayoutDocument child in currentContentsList)
{
child.IsActive = true;
}
推荐阅读
- javascript - Vue JS 无法将 innerHTML 的属性设置为 null
- ipfs - 将文件夹中的文件固定到 pinata 上的 IPFS 时,是什么决定了 gateway.pinata.cloud/ipfs 链接?
- web - 在 Cloud Foundry 上部署 Web 应用程序给出 fileNotFoundException
- python - 带有 API 谷歌表的 Discord Bot
- google-apps-script - Google 表格 - 按钮不断移动
- html - 滚动时将页眉固定在顶部
- amazon-web-services - 如果相同事件类型的前缀重叠,则无服务器不能在两个规则中具有重叠的后缀
- reactjs - 如何使用useState在对象中只设置一个属性?
- python - 使用 mongoengine 批量插入或更新
- dns - 具有 www 以外的前缀的网站域有什么意义?