In Avalondock, how I find a LayoutContent by ConentId
Asked Answered
C

1

7

I have several panes containing content that all have their ContentIds. I want to be able to find one of the panes so I can set it to the active content. Let's call that MyContentView. In a different view, I press a button that does something like this:

LayoutContent content = FindContentById("myContent");
if(content == null)
{
    content = new MyContentView();
    content.ContentId = "myContent";
    this.MyLayoutDocumentPane.Children.Add(content);
}

this.MyDockingManager.ActiveContent = content;

I can't just hold on to that content because I will later serialize the layout, close the app, and deserialize on startup. This code will not run and I will not have that reference.

Why not just loop down the MyLayoutDocument Pane children? MyContentView can float and when that happens, it is no longer in that container.

Cartesian answered 9/7, 2015 at 23:27 Comment(0)
C
8

You can enumerate through all existing LayoutContent items, regardless of what container they are in, as follows:

foreach (var lc in dockingManager.Layout.Descendents().OfType<LayoutContent>())
{ /* do something */ }

Descendents() is an extension method contained in the Xceed.Wpf.AvalonDock.Layout.Extensions static class, so you have to add this using:

using Xceed.Wpf.AvalonDock.Layout;
Clothier answered 20/7, 2015 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.