Catel custom View creation

129 views Asked by At

I would like to create custom window and show it without IUIvisualizerService with Catel.

The problem is: When I create a window, bind ViewModel to it, seems like View does not react on properties changes.

I have done following:

var photo = new Photo();
NewPhotoWindow newPhotoWindow = new NewPhotoWindow();
var viewModel = new NewPhotoWindowViewModel(photo);
newPhotoWindow.DataContext = viewModel;

newPhotoWindow.ShowDialog();

Is there a way to create it via some kind of ViewLocator?

I have tried with TypeFactory, but this does not allow me to put photo as a model for my ViewModel.

1

There are 1 answers

3
Geert van Horrik On

You shouldn't be manually doing the ViewModel creation in Catel. It's all done for you automatically.

This should be sufficient:

uiVisualizerService.ShowDialog<NewPhotoWindow>();

This will automatically:

  1. Resolve the VM that belongs to NewPhotoWindow (NewPhotoWindowViewModel or NewPhotoViewModel).
  2. Instantiate the VM using IViewModelFactory
  3. Create the window and set the vm to it