I have 3 ViewModels:
- App.ViewModels.LoginViewModel
- App.ViewModels.NavigationViewModel
- App.ViewModels.AbcViewModel
and 3 Views:
- App.Views.LoginView
- App.Views.NavigationView
- App.Views.AbcView
In my AppBootstrapper, LoginView is loaded like so:
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
var windowManager = IoC.Get<IWindowManager>();
var loginModel = IoC.Get<ILogin>("Login");
windowManager.ShowWindow(loginModel, "LoginView");
}
However, this returns that the view cannot be found for that ViewModel. Unless I change the namespace of the LoginView to App.Views.Login.LoginView and leave the VM namespace as it is. It then works fine.
After a succesfful login, I use the same process to load my NavigationViewModel. (After having changed the namespace to the App.Views.Navigation.NavigationViewModel so that it actually works)
Currently, this leaves me with the following namespaces for the views:
- App.Views.Login.LoginView
- App.Views.Navigation.NavigationView
- App.Views.AbcView
NavigationViewModel is a conductor, it has a list of ViewModels and a TabControl on the view to display them.
Unfortunately I then have to manually bind my AbcViewModel to the view, otherwise nothing gets displayed. For example:
AbcView abcv= new AbcView ();
AbcViewModel abcvm= IoC.Get<AbcViewModel>("Abc");
ViewModelBinder.Bind(abcvm, abc, null);
I want everything to be done using the Caliburn ViewModel first approach, so that adding new ViewModels and Views I don't need to worry about binding the view manually. I've adhered to the structure and yet it isn't working. Where am I going wrong?
Basically, is there a way that caliburn can create and then bind my view when I create my ViewModel? Do I need to somehow call the ViewLocator for each of my models? If so, how is this any different to the manual bind that I'm doing at the moment?
Does anyone know of a full example (Whole project) of a view model first caliburn project that I can sneak a look at?
Any help appreciated, thanks in advance.
Matt