March 6, 2010
A few days ago I received a comment from someone named Joe on my blog. He was expressing concern over several aspects of my book Advanced MVVM, including the fact that it is written about a relatively simple game, not something more complicated. After Joe read the book his apprehensions about it disappeared, and he kindly left me this comment:
Ok, after reading your book, I have to say “Wow!” Not only have you managed to help me understand some of the frustrations I had with MVVM development, but your book also made some good points (which I shared with my development manager) and reinforced with real examples of issues I faced working on a project using that pattern.
I was very (pleasantly) surprised reading your take on the code-behind vs. NO code-behind mentality. I myself prefer the middle ground, but for some time was forced to do the latter. Yes, it did create several layers of very difficult to follow, understand and maintain code; from your notes and my examples, I was able to reach a compromise on how we should utilize ‘code-behind’.
Now, an interesting story –our architect chose the MVVM pattern after reading your article in MSDN in 2009. However, they chose to enforce “no code-behind” at all for the sake of testability.
The book is awesome; if you can mix MVVM with Prism and come up with a nice 300+ page book with some nice distilled information like that, I’d a) like to help write it; and b) shell out at least $50.00.
P.S. you’re right, there is no “Silver Bullet”; however, it would be nice to have some guide or set of documentation as to what works well when and where, especially when certain design patterns are applied to solve a problem.
It sounds like Advanced MVVM has another happy customer!
February 25, 2010
I finally found a way to reproduce a minor issue in BubbleBurst, the application reviewed in my Advanced MVVM book. I fixed the issue, which had to do with bursting a bubble group during an animated undo transition, and updated the source code and download files on CodePlex. If you’re interested in seeing the fix, it’s associated with changeset 43211.
By the way, I would like to thank all of you who have bought Advanced MVVM. I am shocked at how many copies have sold so far. This far exceeds my expectations!
February 15, 2010
I have been working tirelessly for weeks on what I consider to be my masterpiece. I’ve published a book called Advanced MVVM. It is a 52 page deep dive into some complex problems and solutions in an MVVM application I wrote, called BubbleBurst.
You can buy a hard copy, or a digital copy which can be read in the free Adobe Digital Editions e-book reader. It is also possible to read the book on your Amazon Kindle, by purchasing it here.
The full source code is available on CodePlex: http://bubbleburst.codeplex.com/
The e-book’s Table of Contents is shown below:
Chapter 1 – Introduction
- The Demo Application
- The Source Code
Chapter 2 – Brief Overview of WPF and MVVM
- Learn More about WPF
- Learn More about MVVM
Chapter 3 – View Architecture Overview
- What Should a View Do?
Chapter 4 – ViewModel Architecture Overview
- Core ViewModel Classes
- Creating Bubbles with BubbleFactory
- Finding Bubble Groups
- A ViewModel is a Model of a View
Chapter 5 – Animated Transitions
- What is an Animated Transition?
- Designing for Animated Transitions
- Animated Transitions in BubbleBurst
- Creating Animated Transitions in the ViewModel
- Displaying Animated Transitions in the View
Chapter 6 – Unlimited Undo with Animated Transitions
- Responding to User Input
- Creating Undo Tasks
- Managing Bubble Locations
- Benefits of a Task-based Architecture
Chapter 7 – The Game-Over Dialog
- Opening the GameOver Dialog
- Closing the GameOver Dialog
Chapter 8 – Recap
About the Author
If you are interested in learning more about my e-book, please click here.
November 16, 2009
I spent the weekend having a blast writing a WPF app that displays an interactive object graph, and detects/highlights circular dependencies. It was so much fun, that I decided to publish an article about it on CodeProject.
Here’s a screenshot of the app:
The app uses Charles Petzold’s ArrowLine element, PropertyObserver and ObservableObject from my MVVM Foundation library, DragCanvas from WPF.JoshSmith, and ContentControl3D from Thriple.
If you want to check it out, here’s the article:
October 24, 2009
When working on large WPF or Silverlight applications, you can end up with a lot of XAML files. If you are using the MVVM pattern, many of those XAML files contain a View whose DataContext is expected to be set to a certain type of ViewModel object. It can sometimes become difficult to remember which Views expects which ViewModel as their DataContext. One very simple and lightweight way to help you and your team remember a View’s expected DataContext type is to leave an XML comment at the top of the XAML file. This incredibly simple and obvious technique can be a HUGE timesaver later on down the road!
I highly suggest that you get into the habit of doing this, if you haven’t done so already. You will thank yourself many times later…
September 7, 2009
I just published an article about a technique I use to streamline and simplify the way that ViewModels are created in an MVVM app. I’m not saying that this is the “right” way to do things, but simply something I find useful. Enjoy!
August 23, 2009
I set aside some time today to add some goodness, and remove some badness, from my MVVM Foundation library on CodePlex. Special thanks go to Matt Heffron for his great work on making the Messenger class much safer and user-friendly. Here is a listing of the changes:
- Added safety checks and helpful error messages in Messenger for callback registration and message broadcasting. Unit tests were added to verify this behavior.
- Ensured that Messenger notifies colleagues of a message in the order they registered for that message. Unit tests were added to verify this behavior.
- Fixed an issue in an ObservableObject unit test where it failed in a Release build.
It’s exciting for me to see the improvements and ideas suggested by people using MVVM Foundation! I appreciate the time people have contributed toward making the library better. I hope there are no hard feelings when I reject a proposed feature. :)
You can get the latest source code here: http://mvvmfoundation.codeplex.com/SourceControl/ListDownloadableCommits.aspx
July 15, 2009
I just added a demo application to the MVVM Foundation project on CodePlex. It is contrived, but shows how to use ViewModelBase, RelayCommand, PropertyObserver, and Messenger. You can download the latest source code here.
July 14, 2009
Today I published a new CodePlex project, called MVVM Foundation. It is a library of my favorite classes to use in MVVM applications. Right now, it only contains classes suited for WPF applications, but eventually I will get around to adding in a Silverlight version, too. If you would like to check it out, here’s the link:
July 11, 2009
EDIT: Shortly after publishing this blog post, I received some excellent feedback on it, and updated the PropertyObserver class to implement IWeakEventListener. Special thanks go to Huseyin Tufekcilerli for posting an IWeakEventListener implementation, which got me 90% of the way toward a better solution. This blog post and its source code download have been updated to reflect this improvement.
When working with objects that implement INotifyPropertyChanged, as most ViewModel objects tend to do, it often becomes necessary to attach a handler to their PropertyChanged event. Your code can quickly accumulate many event handling methods full of conditional statements that check if e.PropertyName equals some hard-coded string value. This leads to messy, brittle code that becomes difficult to maintain as the mess gets larger.
To combat this evil, I decided to mechanize as much of this as possible. I created a generic class called PropertyObserver<TPropertySource> which monitors the PropertyChanged event of an object, and executes whatever callback methods you have registered for when certain properties have changed. In addition, that class will verify that every property name you register with it is a real, public property on the object being observed, because the way that you provide the property name is checked by the compiler (you pass it a lambda expression that references the property). If a property name changes, but you forgot to update your code that registers the property with PropertyObserver, you will get a compiler error next time you try to build your solution.
Here are the two methods of interest:
Here is a simple example, from the source code download, that shows how to use PropertyObserver:
You can download the source code here. Note: Change the file extension from .DOC to .ZIP and then decompress it.