I had a talk with Kaj Lund from Attracts; they are using the ViewModels for WPF. He felt that the use of a DataGrid in every detail list is a bit “too much”. For example if there is only one column to display, and that you do not want to allow edit or allow user sorting a ListView might be a much more natural choice.
This is a dilemma for all declarative development; you often get a “one size fits all” scenario. Of course there is a way around it… Our take on declarative development aims to remove all the un-necessary degrees of freedom but still leave you in full command. In this case I suggested that Kaj should use the ViewModelWPFUserControl.OnColumnUIOverride event.
This event fires before each component is created and you can create your own based on the given circumstances. Probably you have a set of UI rules in you project like if the details grid only contains 1 column it should be a ListView instead (or whatever).
So this is one way to implement this event in xaml:
And in code:
What the code does is in this case: 1. Verify that this column has the StyleRef==”DisplayInListView” and some other prerequisites that I decided should control the use of the ListView.
Then I set e.ContinueWithDefault=false to stop the standard behavior. And then I just add a ListView in the correct position and bind it to the data…
Voilá, we have extended our rule base for the declarative development provided by ViewModels.