How to programmatically set Model.View?

Sep 13, 2011 at 4:14 PM

Hello,

I use the AvalonDock library, which unfortunately doesn't support XAML code like this:

<UserControl.Resources>
        <DataTemplate DataType="{x:Type ViewModels:MatchAnalysisChildViewModel}">
            <ad:DockableContent Title="{Binding DisplayName}" IsCloseable="True">
                <ContentControl Micro:View.Model="{Binding}" />
            </ad:DockableContent>
        </DataTemplate>
    </UserControl.Resources>
    <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <ad:DockingManager>
            <ad:ResizingPanel Orientation="Horizontal">
                <ad:DockablePane ItemsSource="{Binding ViewModels, Converter={StaticResource screenToDockableContentConverter}}" />
                <ad:DockablePane>
                    <ad:DockableContent Title="Video Player" IsCloseable="True">
                        <ContentControl Micro:View.Model="{Binding VideoPlayer}" />
                    </ad:DockableContent>
                </ad:DockablePane>
            </ad:ResizingPanel>
        </ad:DockingManager>
    </DockPanel>

As a workaround, I'm trying to create a converter, which would create a new DockableContent instance from a screen. But I don't succeed in translating the Micro:View.Model="{Binding}" in code...

How could I achieve this?

Thanks in advance

Mike 

Sep 21, 2011 at 12:20 AM

var binding = new Binding();
BindingOperations.SetBinding(theElement, Caliburn.Micro.View.ModelProperty, binding);