This project has moved. For the latest updates, please go here.

shellViewModel.ContentView is still null after assignment

Sep 8, 2011 at 8:04 AM

Hi, I'm having a confusing problem with WAF in that in my ApplicationController's Run method, even after assigning

shellViewModel.ContentView = mainViewModel.View

shellViewModel.ContentView is still null. I have no explanation for this, as I've stepped through the entire startup and there's no hint of any exception or problem along the way. I've checked my structure in terms of the Writer sample and they're quite similar (I've left a lot out of it for simplicity to start with.) Does anyone have any hints on where I could look to see what the problem is?

The source can be found here (line 49): https://github.com/QUTOS/BioDome/blob/master/BioDome.Applications/Controllers/ApplicationController.cs

Another question is have while I'm here is: When is it appropriate to create a new controller? I was under the impression they were just for dialog/wizard type operations, though I think there could be a more precise explanation.

Thanks,
George

Coordinator
Sep 8, 2011 at 5:37 PM

Hi, You made a little mistace in the ShellViewModel.ContentView property:

set
{
    if(contentView != null)
    {
        contentView = value;
        RaisePropertyChanged("ContentView");
    }
}


Your code shows if (contentView != null). This way the property is never set.

Correct: if (contentView != value).

Controllers: It’s not always easy to decide what the ViewModel and what the Controller is responsible for. I like to keep the responsibilities of the ViewModel low (Single Responsibility Principle) and put the more advanced operations into the Controller. Tasks which involve more than one ViewModel should always be implemented in Controllers. So the ViewModels don’t need to know each other and the Controllers mediate between them.

Best Regards,
  jbe