Being declarative when it fits with the Model Driven Framework ECO for Visual Studio 2010

So I always praise this declarative development that Enterprise Core Objects lends itself to. Take the ViewModels – I go on and on, post after post, rambling on how amazingly fast and robust a UI built this way can be delivered.

But what if I want something really special in my UI – something that the ViewModel engine does not support. If I have do abandon the technique then I might as well skip it in the first place some might argue. Point taken. This post is for you.

Content Override


In the ViewModel – editor above I have marked a little checkbox called “Content override” with red. And I also marked how it is rendered in the preview – like  a square that says “OVERRIDE”. This is one way to get “odd” things into the otherwise purely declaratively defined UI.

When a ViewModel column has the “Content Override” set, an event will fire on the ViewModelUserControl (same for Silverlight, WPF, ASP.NET and windows forms), and in this event you can pretty much do want you want with the data provided for that column.

In code it can look something like this:

Code Snippet
  1. // Set up the event handler
  2. EATree_Step_UC.SetEcoSpace(es);
  3. EATree_Step_UC.OnColumnUIOverride +=
  4. new EventHandler<OnColumnUIOverrideArgs>(EATree_Step_UC_OnColumnUIOverride);
  7. // Implement the event
  8. void EATree_Step_UC_OnColumnUIOverride(object sender, OnColumnUIOverrideArgs e)
  9. {
  10.     if (e.ViewModelColumn.ContentOverride)
  11.     {
  12.         Grid g=e.ViewModelColumn.SpawnedArtifacts["control"] as Grid;
  14.         if (e.ViewModelColumn.Name=="CompleteStepDraw")
  15.         {
  16.       g.DataContextChanged += new DependencyPropertyChangedEventHandler
  17.           (g_DataContextChanged_CompleteStepDraw);
  18.             g_DataContextChanged_CompleteStepDraw(g,
  19. new DependencyPropertyChangedEventArgs());// initial init
  20.         }
  21.     }
  22. }

Note the that Override area is implemented as a Grid in WPF and Silverlight and you can add the things you want to show up here with another user control or what have you. The result of the expression for the column will be in DataContext for that very Grid.

In my case it turned out like this:


Fast, flexible and low maintenance for standard UI –  what is not to like?

This entry was posted in Declarative, ViewModel, Xaml. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.