first_page

Flippant Remarks, Yet Again about WPF/MVVM…

This is supposed to be a Blog about the Blues and poetry—and the kintespace.com Web site, right? What about Amiri Baraka in Los Angeles last weekend…? Well, the mothers of my two youngest children went to see him Sunday night. That night, my youngest son tricked me into driving through a McDonald’s drive-through after his bedtime—I knew his mother would never take him to McDonalds… but, then again, one never knows until one knows…

Anyway WPF takes us from eventing and imperative data binding (in Windows Forms) to commanding and declarative data binding. This is a huge leap! The System.Windows.Data namespace and additions to System.ComponentModel (like ICollectionView) make this possible. More Josh-Smith source code:ICollectionView collectionView = CollectionViewSource.GetDefaultView(this.Workspaces);

if (collectionView != null) collectionView.MoveCurrentTo(workspace); The Workspaces we see represent a collection of View Model objects—so don’t let that term “space” in Workspaces referring to a non-visual concern bug you (I’ll do that for you—hey, I’m the guy who coined kinté space). Okay, my point is that MoveCurrentTo() moves a View Model—only because this View Model is bound to a View (through a DataTemplate) do we see the UI update. I ranted about typed DataTemplate objects earlier. The declarative binding of typed DataTemplate objects makes this awesomeness possible!

All of this “workspace” switching in the UI has to be declared by a parent XAML element—that element should have a ContentControl.Content property. This property is bound to Workspaces in our example above like this:<HeaderedContentControl Content="{Binding Path=Workspaces}" /> This describes most of the ‘wiring’ mentioned in earlier. Okay. Great… Now, on to other non-poetry-related topics (it’s all poetry to me):

  • In Jason Dolinger’s MVVM video, at about 1:10 he starts into getting static data to show up in Blend to make MVVM stuff designer-friendly.
  • Jason also shows where the decorator pattern is important when “wrapping” a WPF service object in a dispatcher.
  • I’m packing away DispatcherObject extension methods by Eric De Carufel that I assume will come in handy when calling into the UI thread.

rasx()