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.
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.
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.
Solution and project structure
Video covers the how and why the solution and projects are structured the way they are.
Introduction to OData
Video gives a short introduction to OData and querying OData sources.
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.
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.
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.
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.
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.
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).
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.
Video explains the VisualStateAssistant AttachedProperty that enables the changing of VisualStates in the UI from a ViewModel using data binding.
Behaviors in Stuff
Video explains the Expression behaviors used in the Stuff application and how to wire them up.
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.
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.
I will post the VB.NET source code Monday evening, 10 May.
C# Source Code
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#
, Visual Studio 2010
, WPF Business Application Series
, WPF Controls
, WPF General