Is MVVM dead in Windows 8 Store Apps?

Poul K. Sørensen picture Poul K. Sørensen · Sep 15, 2012 · Viewed 8.9k times · Source

I have started learning about Windows 8 Store Apps.

I recall from Silverlight and WPF programming earlier that people adapted the MVVM concept and now I am not sure if I should use what i learned back then or not.

I added a reference to the GalaSoft.MvvmLight and created a ViewModel and added it to my xaml as suggested by:

DataContext="{Binding Source={StaticResource Locator}, Path=Welcome}"

It looks like Microsoft included some kind of ModelView implementation in the LayoutAwarePage:

protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
    // TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
    //  DefaultViewModel["WelcomeTiles"] = WelcomeTiles;
}

which can be accessed if following datacontext have been set.

<DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" />

So now I am unsure if I should create ModelViews as i remember them, by using MVVMLight or just add the data in code-behind files to the DefaultViewModel.

What are peoples experience with both? I have just started and my next goal is to add handlers for when a item is clicked in the GridView - which of the above paths will let do so in a easy way?

Answer

ColinE picture ColinE · Sep 16, 2012

No, MVVM will never die!

Model-View-ViewModel is a design pattern, so it is not dependent on a specific framework or implementation. However, it is a UI design pattern that is most convenient to use with UI frameworks that support data-binding.

Windows 8 Metro apps include XAML and a binding framework which is much like Silverlight and WPF. For this reason, MVVM is excellent choice for managing your code.

The code you have discovered in LayoutAwarePage is described in this blog post. It is an attempt to make Windows 8 Metro app development easier by providing various stub-implementations. This page includes a DefaultViewModel, which is an observable dictionary.

Personally, I wouldn't use it!