Can't find ViewModel for Telerik RadWindow

Feb 7, 2012 at 1:32 PM

'm trying to open a Telerik RadWindow, 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?

Coordinator
Feb 7, 2012 at 6:07 PM

You sholdn't be passing radWindowViewModel as the third parameter in the LocateForModelType call. Also, the locator only locates a view, it does not bind them. You will nee to use the Binder for that. For a look at how this whole thing works end to end, have a look a the WindowManager class. Unless you really need RadWindow, you might consider just using the WindowManager. There's a sample in the download that shows how to use it.

Feb 7, 2012 at 6:49 PM

Thanks, ViewModelBinder.Bind is what I was missing :)

Feb 8, 2012 at 4:45 PM

Erik - do you mind posting your final implementation.  I've been meaning to play with the RadWindow (since I'm paying for it).

Thanks

jack

Feb 8, 2012 at 5:36 PM

            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();

 

Now I still get an error in the VS output window, I don't know what causes it or how to fix it:

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')

Feb 9, 2012 at 5:31 PM

Here's a Telerik RadWindowConductor.

https://github.com/vcaraulean/Caliburn.Micro.Telerik

https://github.com/vcaraulean/Caliburn.Micro.Telerik/blob/master/Caliburn.Micro.Telerik/RadWindowConductor.cs