Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Stuff – WPF Line of Business Using MVVM Video Tutorial

0.00/5 (No votes)
8 Jan 2015 1  
Stuff – WPF Line of Business using MVVM Video Tutorial

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 to 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 cannot 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 it's not needed. Instead, when appropriate, I make mention 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 APIs 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 advanced 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 bind 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 get the 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 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 enable 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

If you have not installed Expression Blend 4, then your system will not have the Expression Blend SDK assemblies and you won’t be able to compile the solution.

I have added a folder to the solution named, “Expression SDK Dlls.” If you do not have Blend installed, you’ll need to update the references to the Blend SDK assemblies by removing the broken references and re-adding the reference to the DLL in the above folder.

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here