Can't find ViewModel for RadWindow using Caliburn.Micro

2 posts, 0 answers
  1. Erik
    Erik avatar
    24 posts
    Member since:
    Nov 2010

    Posted 05 Feb 2012 Link to this post

    I'm trying to open a RadWindow in my Caliburn.Micro project, but I'm having trouble tying the dialog's View to the ViewModel.

    In my ViewModel I open the dialog using:
    var radWindowViewModel = new MyViewModel();
    var radWindow = new RadWindow
        {
          Width = 400,
          Height = 150,
          Content = ViewLocator.LocateForModelType(typeof(MyViewModel), null, radWindowViewModel)
       };
    radWindow.ShowDialog();

    The RadWindow is opened, but in it is displayed: "Cannot find view for MyNameSpace.MyViewModel.

    Alternatively, when I set RadWindow.Content the following way:
    Content = ViewLocator.LocateForModel(radWindowViewModel, null, null)

    then I see the correct View, but the View's DataContext is never set.

    Does anyone know what I'm doing wrong?
  2. Erik
    Erik avatar
    24 posts
    Member since:
    Nov 2010

    Posted 07 Feb 2012 Link to this post

    I was missing the ViewModelBinder:

    var radWindowViewModel = new MyViewModel();
    var radWindowView = ViewLocator.LocateForModel(radWindowViewModel, null, null);
    ViewModelBinder.Bind(radWindowViewModel, radWindowView, null);
     
    var radWindow = new RadWindow
    {
       Width = 400,
       Height = 150,
        Content = radWindowView
    };
    radWindow.ShowDialog();

    But I now get the following line in the output:
    System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='<null>' BindingExpression:Path=(0); DataItem='RadWindow' (Name=''); target element is 'WindowHostWindow' (Name=''); target property is 'Title' (type 'String')

    Is there an additional step that I'm missing?
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top