Cursored or non Cursored

Cursored set up is what we call the standard dialog display of one to many relationships. Like in normal master detail displays when the master has a current value, a cursor, that controls what details to show.

The non Cursored set up would be more like a tree – something that displays details for every parent available, not just the parent selected (the current master). This is what treeviews and reports do and it is something we want to be able to do using viewmodels as well.

Consider this model


And this ViewModel:


The ViewModelUserControl uses a cursored set up when generating a UI:

Code Snippet
  1. <StackPanel  Height="262" VerticalAlignment="Top" >
  2.     <Button Background="Yellow" Click="Button_Click">
  3.         <TextBlock Text="Click to Create New and Set in ViewModel" ></TextBlock>
  4.     </Button>
  5.     <viewmodel:ViewModelWPFUserControl Background="Azure" Name="viewModelWPFUserControl1"   
  6.                              EcoSpaceType="{x:Type eco:EcoProject12EcoSpace}"
  7.                              ViewModelName="SampleViewModel" />
  8. </StackPanel>

Giving us this in VisualStudio WPF Designer:


And in this UI the Cursor set up sees to it that the Class3 grid only shows the Class3 objects owned by the current row in the Class2 grid; this is the standard behavior.

Nothing new here for ECO5 developers really.

In ECO6 for Visual Studio 2010 we added a new ViewModel consumer: the BindableViewModel.

This component replaces the ViewModelContent (ViewModelContent is not removed, and BindableViewModel use ViewModelContent under the hood).

The reason for adding BindableViewModel is mainly to provide Design time binding support. This was not possible in the WPF designer for Visual Studio 2008, but it is for Visual Studio 2010.

Check out this code that defines two BindableViewModels one cursored and one that is not cursored:

Code Snippet
  1. <Window.Resources>
  2.      <wecpof:BindableViewModel x:Key="BindVM"
  3.               EcoSpaceType="{x:Type eco:EcoProject12EcoSpace}"
  4.               ViewModelName="SampleViewModel"
  5.               Cursored="True"></wecpof:BindableViewModel>
  6.     <wecpof:BindableViewModel x:Key="BindVM2"
  7.               EcoSpaceType="{x:Type eco:EcoProject12EcoSpace}"
  8.               ViewModelName="SampleViewModel"
  9.               Cursored="False"></wecpof:BindableViewModel>
  10. </Window.Resources>

We can then use the artifacts within the viewmodel.

Check out this treeview that use the non cursored BindableViewModel:

Code Snippet
  1. <StackPanel DataContext="{StaticResource BindVM2 }" Background="Red">
  2.     <TextBlock x:Name="MyTextBlock2"
  3.                Text="{Binding Path=SampleViewModel/Class2/Name}"></TextBlock>
  4.     <TreeView ItemsSource="{Binding Path=SampleViewModel/Class2}" >
  5.         <TreeView.ItemTemplate>
  6.             <HierarchicalDataTemplate ItemsSource="{Binding Path=Class3}" >
  7.                 <HierarchicalDataTemplate.ItemTemplate>
  8.                     <HierarchicalDataTemplate>
  9.                         <TextBlock Text="{Binding Path=AsString}"></TextBlock>
  10.                     </HierarchicalDataTemplate>
  11.                 </HierarchicalDataTemplate.ItemTemplate>
  12.                 <TextBlock Text="{Binding Path=Name}"></TextBlock>
  13.             </HierarchicalDataTemplate>
  14.         </TreeView.ItemTemplate>
  16.     </TreeView>
  17. </StackPanel>

It looks like this at runtime:



Even if you are not going to use the Generated UI capabilities provided by the ViewModelUserControls you can still use the ViewModel-definitions. The ViewModel is a good place to keep any and all transformations you need between your domain layer and your presentation. The ViewModel also holds the infrastructure for verifying OCL expression and for Validation definitions (Described here). And now with the ability to use both a Cursored set up and a non Cursored set up the argument is even stronger. Top this with design time support to the bind to the ViewModel-classes and columns.

This entry was posted in ViewModel. Bookmark the permalink.

One Response to Cursored or non Cursored

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.