May 2010 Entries

WPF Style and Template Resources – Order Matters

When working with WPF resources, remember to declare the resources in the correct order. A style or template that is referenced elsewhere must be defined before it can be used. In other words, if Style1 uses BrushA as a StaticResource, then BrushA must be defined before Style1. Otherwise, you’ll get fun errors like: Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.FrameworkTemplate' It may be common knowledge, but it can be a real pain to diagnose. This is especially true if you have a large set of template and styles for...

posted @ Friday, May 07, 2010 4:44 PM | Feedback (5)

MVVM ViewModel Locator via WPF Converters

Laurent Bugnion’s work on MVVM Light introduced me to the ViewModel Locator pattern. The concept and implementation are really slick! From my perspective, ViewModel Locators do the following: Provide a simple, declarative way to connect a View to a ViewModel (duh). Enable design-time support, including the ability to connect an alternate data source behind the VM (cool!). I want a solution that lets me: Connect my XAML views to their associated ViewModels Handle a somewhat complex model with a hierarchy of domain model entities and...

posted @ Thursday, May 06, 2010 12:05 AM | Feedback (3)