View model not attaching to view in alpha2 release

Topics: Bootstrappers & IoC, Getting Started
Dec 9, 2013 at 1:02 AM
Using the alpha2 release, I can't seem to have any view model code run, although the view shows up fine.

I created a new WP8 project and installed the Caliburn.Micro.Start alpha2 NuGet package. I then removed almost everything from App.xaml.cs per the instructions.

I edited MainPageViewModel to show a message box in its constructor. Pressing F5 shows MainPage.xml, but no popup.

This worked fine in 1.5.2, does anyone know what I may be missing? Here's the sample project reproducing the issue for me: http://sdrv.ms/1cjJm1c
Dec 9, 2013 at 5:17 AM
CM 2.0 uses a new caching mechanism for view and view-model types.
(see https://caliburnmicro.codeplex.com/SourceControl/latest#src/Caliburn.Micro.Platform/AssemblySource.cs)

To detect a class as view-model it has to implement INotifyPropertyChanged what all view-models already do.
Only the nuget start package didn't follow this guidance.

Let the view-model inherit from PropertyChangedBase and your sample will work with CM 2.0 too.
Dec 9, 2013 at 7:05 AM
Thanks, that works. Nice job in committing an updated sample as well!
Dec 9, 2013 at 7:31 AM
Edited Dec 9, 2013 at 7:38 AM
Assuming the MainPageViewModel is in a separate assembly, how and where do we configure this?

I tried adding the following in the bootstrapper constructor and its Configure method:
AssemblySource.Instance.Add(typeof(MainPageViewModel).Assembly);
I also tried the following:
        protected override IEnumerable<Assembly> SelectAssemblies()
        {
            return new[] { 
                GetType().GetTypeInfo().Assembly,
                typeof(MainPageViewModel).GetTypeInfo().Assembly
            };
        }
The breakpoint in my view model constructor never gets hit.
Dec 9, 2013 at 8:01 AM
Edited Dec 9, 2013 at 8:02 AM
You have to override SelectAssemblies() and update the naming conventions so CM will find the view-model.
see https://caliburnmicro.codeplex.com/discussions/348490

But this has nothing to do with changes in CM 2.0, you have to do the same in CM 1.5 for this to work.
Dec 10, 2013 at 7:11 AM
Thanks!