February 2010 Entries

Should the Domain Model implement INotifyPropertyChanged?

I’ve been discussing an architectural question with a colleague this week. The scenario includes a WPF application, Domain Driven Design and MVVM. The goal is a relatively “pure” domain model where the classes in the model do not depend on any UI specific or other external assemblies. They are pretty much pure “POCO” objects. The question is whether it’s reasonable to have the domain model implement INotifyPropertyChanged and INotifyCollectionChanged (via ObservableCollection). INotifyPropertyChanged is defined in System.dll. It’s part of System.ComponentModel namespace. INotifyCollectionChanged and ObservableCollection are both in WindowsBase.dll. These are in System.Collections.Specialized and System.Collections.ObjectModel respectively. My take… go for...

posted @ Friday, February 26, 2010 12:20 AM | Feedback (4)

Skinning WPF – Call InitializeComponent in App.Xaml

For the past two days, I’ve been trying to get the infrastructure in place for skinning a WPF application. My goal is to support multiple skins and swap them out dynamically while the app is open. I could get the skin to affect the UI if I set it in the main window’s resource dictionary. However there was a quirk… The application uses WPF frames and pages. The skin was not showing up on frame’s pages. It would only show up on the main window. I searched Bing, Google and StackOverflow for answers. No luck. I...

posted @ Thursday, February 25, 2010 10:48 PM | Feedback (0)

MVVM: To Wrap or Not to Wrap? BLINQ and CLINQ to the Rescue! (Part 3)

In part 1, I asked the question “Do I expose the model directly, or do I wrap each item in its own view model?” We looked at two plausible options for handling this and saw some code examples of each. In part 2, I asked the question “Do I expose the model’s collections directly, or do I wrap each collection?” We saw the progression of code to implement this "brute-force". Then we quickly ran away screaming. This installment (part 3) asks "How do I cleanly and easily wrap the model’s collections with collections of ViewModels?" We'll take a...

posted @ Tuesday, February 09, 2010 10:45 PM | Feedback (7)

MVVM: To Wrap or Not to Wrap? Should ViewModels wrap collections too? (Part 2)

In my previous post, I asked the question “Do I expose the model directly, or do I wrap each item in its own view model?” We looked at two plausible options for handling this and saw some code examples of each. Now it’s time for a more interesting and challenging scenario: Do I expose the model’s collections directly, or do I wrap each collection? Let me paint this picture a bit so that we can see the scenario and the challenges. MVVM says that a ViewModel sits between the View (XAML) and the Model. The ViewModel (VM) exposes data from the model...

posted @ Tuesday, February 09, 2010 2:48 PM | Feedback (6)

MVVM: To Wrap or Not to Wrap? How much should the ViewModel wrap the Model? (Part 1)

The WPF community seems pretty happy with the MVVM pattern for WPF development. I can see why. It’s a great fit for WPF and its strong data-binding support. It provides a very nice layer for managing UI state, translating, formatting, and aggregating data. So let’s say that I adopt MVVM for my project. I think there are some scenarios that still need definition. One of these is “To Wrap or Not to Wrap?” Let me explain… MVVM says that a ViewModel sits between the View (XAML) and the Model. The ViewModel (VM) exposes data from the model plus additional view-specific details that...

posted @ Tuesday, February 09, 2010 11:11 AM | Feedback (12)

C# Snippets for Properties that support INotifyPropertyChanged

Since WPF likes INotifyPropertyChanged on bound objects, I looked for a snippet to help out. Matthias Shapiro had a good version for the interface implementation and a property declaration. I made a couple adjustments to the snippets based on personal preference (check if the value has changed before raising the event / remove the region from the property. Then added some property verification support based on the snippet sample from Philipp Sumi. The property verification uses reflection to check if the property exists. If not, it throws an exception. This function is marked with a Conditional attribute so that it...

posted @ Monday, February 01, 2010 3:08 PM | Feedback (9)