AvalonDock and ContentControl

Nov 19, 2013 at 10:17 AM
Hello!

I am using AvalonDock in a MVVM-based application.

This has some Viewmodels and loads the corresponding controls out of a datatemplate:
<Window.Resources>
        <ResourceDictionary>            
            <!--DataType for Viewmodel-->
            <DataTemplate  DataType="{x:Type local:MyControlVM}">
                <local:MyControl />
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>

...

<avalondock:DockingManager>
            <avalondock:ResizingPanel Orientation="Vertical">
                    <!--UserControl in DocumentPane-->
                    <avalondock:DocumentPane>
                        <avalondock:DocumentContent>

                                <ContentControl Content="{Binding Path=MainWindow.MainWindowVM.MyControlVM, Source={x:Static app:App.Current}}" />

                        </avalondock:DocumentContent>
                 </avalondock:DocumentPane>
            </avalondock:ResizingPanel>
    </avalondock:DockingManager>
I am using this one
Content="{Binding Path=MainWindow.MainWindowVM.MyControlVM, Source={x:Static app:App.Current}}"
because of the binding problem (I have created a Dependency Property of the Viewmodel on my Mainwindow).

If I run the app, everything works fine, I can float the windows and the keep the binding (and DataTemplate).

But now my problem: if I float the DocumentContent (it's not docked in the MainWindow) and instantiate a new Viewmodel, it doesn't find the corresponding DataTemplate and shows the Result of the ToString()-Method.
Putting the resources in the Appl.xml doesn't help.

Any ideas how I can solve this issue?

Thanks a lot!
Joerg
Nov 19, 2013 at 12:00 PM
Hello,

I could solve this by putting the DataTemplate directly in the ContentControl-Resources.
Works for now.

Regards,
Joerg
Marked as answer by joerg030284 on 11/19/2013 at 5:00 AM