We have a project which has this project assembly structure:
- Training Model
- XAML form which is databound to the model through a mvvm light view model/locator
This all works fine.
On a load event, we reassign the model, effectively:
ViewModelLocator.Main.Training = new Training();
This works fine and the model is still all bound and updates to show the new data on the form.
We want to move the ViewModel outside to its own project/assembly for neatness. I.e. achieve this structure:
- Training Model
- XAML form
- mvvm light view model/locator
Here is the ViewModel:
public class MainViewModel : ViewModelBase
{
private Training training;
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
this.training = new Training();
}
public Training Training
{
get
{
return this.training;
}
set
{
this.training = value;
}
}
}
The ViewModel has a default locator:
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MainViewModel>();
}
public static MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
When I move the ViewModel into it's own assembly and run the project, on the initial run the XAML is data bound correctly to the model instance. On assigning a new Training object as shown above, the form does not update.
What might cause this given that the only thing different is that the mvvw-light view model is in the other assembly?
Thanks