Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Stuff – WPF Line of Business Using MVVM Video Tutorial

, 10 May 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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 po

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)

Share

About the Author

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.
 
Awards:
 
  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog
 
Click here to learn about Mole 2010 debugging tool for Visual Studio 2010
 
Click here to read about XAML Power Toys
 

Just a grain of sand on the worlds beaches.

Follow on   Twitter

Comments and Discussions

 
GeneralISA Server Pinmemberyannduran28-Dec-10 1:52 
GeneralRe: ISA Server PinmemberKarl Shifflett8-Jan-11 4:37 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 10 May 2010
Article Copyright 2010 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid