Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / MFC
Technical Blog

Stuff – WPF Line of Business Using MVVM Video Tutorial

Rate me:
Please Sign up or sign in to vote.
4.43/5 (5 votes)
10 May 2010CPOL6 min read 29.6K   20   7
Stuff is an example application I wrote for WPF Line of Business Tour at Redmond event.  During some of the event sessions I used the code in Stuff to demonstrate topics I was teaching.  During the event, we did not do an end-to-end examination of Stuff, that is the purpose of this bl

Stuff is an example application I wrote for WPF Line of Business Tour at Redmond event.  During some of the event sessions I used the code in Stuff to demonstrate topics I was teaching. 

During the event, we did not do an end-to-end examination of Stuff, that is the purpose of this blog post. 

Stuff

Stuff

In its current form, Stuff is a demo application that allows you to store information about the movies you own.  It uses the Netflix OData cloud database for movie look up, which makes adding a movie to your collection very easy.

One goal for Stuff was that a developer could take the code, open it in Visual Studio 2010 and press F5 and run the application.  I didn’t want burden developers with setting up a database, creating an account to use an on-line service or have to mess with connection strings, etc.

The Netflix OData query service made my goal achievable because it has a very low entry bar.

Stuff v2.  Shortly, I’ll modify Stuff by swapping out the remote data store layers and point it at Amazon’s web service so that I can not only look up movies but books, music and games too.  The reason I didn’t do this up front was because developers would have to go and get an Amazon account just to use and learn from the application. 

Another goal I had for Stuff was to limit referencing other assemblies or frameworks including my own.  All the code for Stuff is in the solution except the Prism EventAggregator.  I hope that trimming the code down to exactly what is being used in the application helps with the learning process.

There is a complete solution in both C# and VB.NET.

Model-View-ViewModel

You won’t see an individual video on MVVM below, because its not needed.  Instead, when appropriate I make mention of MVVM in the videos.

MVVM is a super simple pattern that describes a way to think about WPF and Silverlight applications.  When thinking in MVVM, we think in terms of a Model (our data), View (our UI) and ViewModel (traffic cop, abstraction of the View and adapter for the Model all rolled up into a single class). 

The Model, View and ViewModel typically communicate using the rich data binding stacks of WPF and Silverlight.

MVVM stands by itself and does not require an additional framework or special skills to use. 

I’ve seen developers investigating MVVM get discouraged when they see MVVM applications that take advantage of advanced features like IOC containers, service locators or MEF; in-effect lumping other programming concepts or API’s into MVVM.  If this happened to you, take a step back and get to know and understand MVVM for what it is, “a way to think about WPF and Silverlight applications.”

When writing WPF or Silverlight applications you may want to take advantage of an IOC container, service locator or MEF, but these are not required to use the MVVM pattern in your applications. 

As you gain experience in how you think about WPF and Silverlight application architecture and design patterns used to create these applications, you’ll find that the advance concepts are actually not that difficult and really do add value to your projects.

If MVVM is new to you, take it slowly, the light will come on.  For example, when you think about a Button, instead of thinking in terms of the Click event handler, you’ll think about data binding the Button’s Command property to an ICommand property on the ViewModel;  instead of thinking about addressing a control in the code-behind file by name, you’ll ask yourself, “what property do I need to expose on my ViewModel” that the UI control can data binding to.

MVVM is a very natural way to think about WPF and Silverlight applications, enjoy the learning journey and have fun.

Stuff Application Video Tutorial

Instead of writing a long blog post, I decided to tell the Stuff application’s story through a series of 14 short videos on different topics. 

I’ve tried real hard to keep each of the following videos short and focused.  The videos are all 1400 x 900.  To the get most from the videos, please read this very short blog post Karl’s Vimeo videos.

Introduction to the Stuff application

Video covers using the Stuff application and where Stuff stores your data locally.

http://www.vimeo.com/11582022

Solution and project structure

Video covers the how and why the solution and projects are structured the way they are.

http://www.vimeo.com/11582296

Introduction to OData

Video gives a short introduction to OData and querying OData sources.

http://www.vimeo.com/11583198

Abstracting the remote data store

Video explains how the Stuff application abstracts the remote data store for the purpose of allowing the concrete implementation to be easily changed in the future or for test purposes. 

http://www.vimeo.com/11453412

Business Entity Objects

Video explains the entity objects used in Stuff.  A short explanation of how I implemented searching the local Stuff data store is also provided.

http://www.vimeo.com/11584004

BusinessEntityBase and Validation

Video explains the BusinessEntityBase class and entity validation in Stuff.  Stuff uses the Data Annotations attributes to decorate class properties with validation rules.  This is a proof of concept that I wanted to try to see how far Data Annotations would take me.

http://www.vimeo.com/11585675

Service Container

Video explains the ServiceContainer (ServiceLocator) used in Stuff.  ServiceContainers provide a mechanism for resolving concrete types at run-time, design-time and test-time for the various services your application exposes.

http://www.vimeo.com/11455192

IDialogService

Video explains how simple it is to implement a dialog service that your ViewModels can consume.  The swapping out of the concrete implementation is also covered.

http://www.vimeo.com/11455208

IEventAggregatorService

Video introduces the Prism Event Aggregator and how Stuff implements an IEventAggregatorService.  Event Aggregator enables creating decoupled applications by disconnecting the initiating object (publisher) from the receiving object (subscriber).

http://www.vimeo.com/11585963

IMovieDataStoreService

Video covers the local data store used by Stuff to persist its data.  Additionally, it explains how local binary serialization and deserialization is used for loading and saving data and how to workaround a problem with binary deserialization in Expression Blend 3 and 4 that is caused by Blend not reloading its application domains between builds.

http://www.vimeo.com/11586513

VisualStateAssistant AttachedProperty

Video explains the VisualStateAssistant AttachedProperty that enables the changing of VisualStates in the UI from a ViewModel using data binding.

http://www.vimeo.com/11586881

Behaviors in Stuff

Video explains the Expression behaviors used in the Stuff application and how to wire them up.

http://www.vimeo.com/11587047

Design-time Visual Studio and Blend support

Video explains what I did to enabled a good design-time experience in the Stuff application in both Visual Studio and Expression Blend.  Video covers the design-time services and design-time data as well as some issues you need to deal with with each of the tools.

http://www.vimeo.com/11590320

Dispatcher, BackgroundWorker and WebClient

Video covers the use of the Dispatcher in the Stuff application and how I used posting to the Dispatcher to set focus to controls after UI transitions.  I also cover using the BackgroundWorker for performing background  search operations and using the WebClient to asynchronously download images.

http://www.vimeo.com/11590982

Downloads

I will post the VB.NET source code Monday evening, 10 May.

C# Source Code

Close

Hope you can learn just a little bit more about WPF Line of Business application programming from this example.

Have a great day,

Just a grain of sand on the worlds beaches.


Filed under: C#, CodeProject, M-V-VM, MVVM, VB.NET, Visual Studio 2010, WPF Business Application Series, WPF Controls, WPF General

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralISA Server Pin
yannduran28-Dec-10 0:52
yannduran28-Dec-10 0:52 
GeneralRe: ISA Server Pin
User 2710098-Jan-11 3:37
User 2710098-Jan-11 3:37 
GeneralMy vote of 5 Pin
sagarok10-Aug-10 20:29
sagarok10-Aug-10 20:29 
GeneralGreat Stuff :) Pin
sagarok10-Aug-10 20:27
sagarok10-Aug-10 20:27 
GeneralCode for this sample Pin
codersoo14-May-10 22:07
codersoo14-May-10 22:07 
GeneralRe: Code for this sample Pin
User 27100915-May-10 12:22
User 27100915-May-10 12:22 
GeneralRe: Code for this sample Pin
User 27100915-May-10 12:22
User 27100915-May-10 12:22 
Look for the Downloads section at the bottom.
Cheers, Karl

My Blog | Mole's Home Page |
XAML Power Toys Home Page

Just a grain of sand on the worlds beaches.



modified 27-Feb-21 21:01pm.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.