Cannot get Caliburn.Micro and the ModernUI to bind

May 6, 2013 at 6:49 PM
I have tried to use the ContentLoader described in the thread: 436518, but i always get a null fro the VM.
public class CaliburnContentLoader : DefaultContentLoader
{
    protected override object LoadContent(Uri uri)
    {
        var content = base.LoadContent(uri);
        if (content == null)
            return content;

        var vm = Caliburn.Micro.ViewModelLocator.LocateForView(content);
        if (vm == null)
            return content;

        if (content is DependencyObject)
        {
            Caliburn.Micro.ViewModelBinder.Bind(vm, content as DependencyObject, null);
        }
        return content;
    }
}
I have a link which i link to the view /Views/TerminalView.xaml. This then enters in the CaliburnContentLoader and looks for the VM. But vm is always null. Content is the right object type of my View. I am not sure what i am doing wrong to find the vm. I am using the Caliburn.Micro SimpleContainer. The link xaml i am using is:
<mui:Link DisplayName="Terminal" Source="/Views/TerminalView.xaml" />
If I navigate using Caliburn.Micro's way of ActivateItem, everything works fine and all the views are loaded. But i cannot then use the ModernWindow.
May 7, 2013 at 8:33 PM
Hey,
Would you Kind sharing a very basic APP showing how Tod combine caliburn micro and modern ui? I just don't geht a grip combining them.
May 7, 2013 at 9:42 PM
Edited May 7, 2013 at 9:42 PM
The way i explain above will cause binding not to work because the viewmodel is never found for the view.

So i just use it as a theme right now. But i would love to use the ModernWindow if i can figure out why the viewmodel is not found.

The way i use it as a theme is to only modify the app.xaml file:
<Application.Resources>
<ResourceDictionary>
<!-- WPF 4.0 workaround -->
<Style TargetType="{x:Type Rectangle}" />
<!-- end of workaround -->
<ResourceDictionary.MergedDictionaries>
  <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
  <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Or just follow the example in the documentation: My first Modern UI app (manually)
This does not work for Caliburn.Micro though.
To add the CaliburnContentLoader , just add these lines to the above example.


App.xaml
<Application.Resources>
<ResourceDictionary>
<!-- WPF 4.0 workaround -->
<Style TargetType="{x:Type Rectangle}" />
<!-- end of workaround -->
<ResourceDictionary.MergedDictionaries>
  <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
  <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
    <ResourceDictionary>
        <local:CaliburnContentLoader x:Key="CaliburnContentLoader" />
    </ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Window.xaml
<mui:ModernWindow
    ...
    ContentLoader="{StaticResource CaliburnContentLoader}">