Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is MVVM dead in Windows 8 Store Apps?

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?

like image 455
Poul K. Sørensen Avatar asked Sep 15 '12 16:09

Poul K. Sørensen


4 Answers

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!

like image 200
ColinE Avatar answered Oct 20 '22 06:10

ColinE


Nope MVVM isn't dead and is still pretty alive!!!

ColinE defintion of MVVM resumes it pretty well. Indeed MVVM is basically a design pattern, and is not dependant to a specific framework.

Using MVVM is not a dogma..., though most who worked a lot with XAML app programming [WPF, Silverlight, WP 7 and WinRT...] will agree that MVVM truely facilitates a clear SOC separation of concern, between the development of the GUI and back end logic.

I've personally used Laurent Bugnion's MVVMLight package from Nuget in combination with WinRT, though you're free to use any other MVVM package or option you feel at ease with.

If you need further sample refs, I would invite you to have a look at the following recording of a webinar on 'MVVM in Windows 8 Store' by Gill Cleeren

http://www.silverlightshow.net/video/MVVM-in-Win8-Webinar.aspx

like image 4
DChamberland Avatar answered Oct 20 '22 08:10

DChamberland


MVVM is not dead in Windows 8 Metro apps.

We didn't use MvvmLight in our app, but the basic components you need, like binding to ViewModel properties, using ICommands in the ViewModel and INotifyPropertyChanged are all available with very minor changes (if any).

Microsoft published a nice sample recently. It doesn't say MVVM explicitly, but it has what you need to get started. And Josh Smith's article is of course still useful.

like image 3
Debrain Avatar answered Oct 20 '22 06:10

Debrain


I recommend http://stylemvvm.codeplex.com, It's written from the ground up to support Metro projects (C#, C++/CX, HTML/JS). It includes a full IOC, implementation for ICommand & Attached Command Behaviors, Services for Tiles, badges, Toasts and Charms. It also includes a nice Mediator class that is dispatcher aware. Plus a number of visual studio templates to help get you started.

Note: I might be biased since I wrote it :)

like image 3
Ian Johnson Avatar answered Oct 20 '22 08:10

Ian Johnson