This is a migrated thread and some comments may be shown as answers.

Can't find ViewModel for RadWindow using Caliburn.Micro

1 Answer 109 Views
Window
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 05 Feb 2012, 06:17 PM
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?

1 Answer, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
answered on 07 Feb 2012, 07:53 PM
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?
Tags
Window
Asked by
Erik
Top achievements
Rank 1
Answers by
Erik
Top achievements
Rank 1
Share this question
or