Take the tour ×

How can I add programmatically LayoutDocument with some of UIElements inside it? (like stackpanel, scrollviewer etc.) I'd like to add new LayoutDocument with stackpanel, canvas etc. to LayoutDocumentPane when user clicks "New project" button. May I somehow clone xaml code from one LayoutDocument and load it's to new one? And is it possible to bind Title LayoutDocument property to ViewModel Property? ( i get error it has to be dependency property )

share|improve this question
add comment

3 Answers

I'm not that familiar with WPF and especially AvalonDock. I did it like this and it works so far :)

You can write a separate class for your documents that inherits from LayoutDocument. In that way you should be able to edit the standard layout of your "Project-Document" with the VisualStudio Designer (add your stackpanel, canvas etc.).

(I assume that you have a standard way of displaying your "Project-Document". Otherwise you could build the content yourself in code behind like you would do in WPF and put it inside the LayoutDocument.)

For example:

<ad:LayoutDocument x:Class="Namespace.MyDocument"

    <!-- content -->


And the class in code behind that inherits from LayoutDocument:

namespace Namespace
    public partial class MyDocument : AvalonDock.Layout.LayoutDocument
        // ...

To create and add a new document you just instantiate a new MyDocument object and add it to the collection via binding or something like layoutDocumentPane.Children.Add(doc).

I don't know about the binding for the Title Property, though.

share|improve this answer
thanks but I've already achieved this with <ad:DockingManager.LayoutItemTemplateSelector>, class which inherit from DataTemplateSelector and DocumentSource={Binding Documents} in ad:Docking manager which is binding to my Document ViewModel. You can also easily bind to Title property using <ad:DockingManager.LayoutItemContainerStyleSelector> just by setting in Style.Setter Property="Title" to a value in your ViewModel. –  fex Oct 5 '12 at 12:45
add comment

You can use Content property. For example if you want to add a new LayoutDocument with a custom content (StackPanel e.g.) you could do it as follow:

//Get the main LayoutDocumentPane of your DockingManager 
var documentPane = dockManager.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();

if (documentPane != null)
    LayoutDocument layoutDocument = new LayoutDocument {Title = "New Document"};

    //*********Here you could add whatever you want***********
    layoutDocument.Content = new StackPanel();

    //Add the new LayoutDocument to the existing array
share|improve this answer
add comment

Thats exactly right. You can add the title by just adding doc.Title = "My document title"


you can add Title="My document title" in the document.xaml which is going to be the child

share|improve this answer
add comment

Your Answer


