I have integrated AvalonDock 2.0 into my application. I\'ve bound the document and anchor-able sources to my view-model which are rendered with the proper user controls via
I had to add this in the XAML...
...
...
...and this in the code-behind...
class LayoutUpdateStrategy : ILayoutUpdateStrategy
{
private bool BeforeInsertContent(LayoutRoot layout, LayoutContent anchorableToShow)
{
var viewModel = (ViewModelBase) anchorableToShow.Content;
var layoutContent = layout.Descendents().OfType().FirstOrDefault(x => x.ContentId == viewModel.ContentId);
if (layoutContent == null)
return false;
layoutContent.Content = anchorableToShow.Content;
// Add layoutContent to it's previous container
var layoutContainer = layoutContent.GetType().GetProperty("PreviousContainer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(layoutContent, null) as ILayoutContainer;
if (layoutContainer is LayoutAnchorablePane)
(layoutContainer as LayoutAnchorablePane).Children.Add(layoutContent as LayoutAnchorable);
else if (layoutContainer is LayoutDocumentPane)
(layoutContainer as LayoutDocumentPane).Children.Add(layoutContent);
else
throw new NotSupportedException();
return true;
}
public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
{
return BeforeInsertContent(layout, anchorableToShow);
}
public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown) {}
public bool BeforeInsertDocument(LayoutRoot layout, LayoutDocument anchorableToShow, ILayoutContainer destinationContainer)
{
return BeforeInsertContent(layout, anchorableToShow);
}
public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown) {}
}