Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Avalondock, how I find a LayoutContent by ConentId

Tags:

c#

avalondock

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.

like image 707
WeatherOracle Avatar asked Jul 09 '15 23:07

WeatherOracle


1 Answers

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;
like image 82
dymanoid Avatar answered Nov 14 '22 22:11

dymanoid