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

 image

And this ViewModel:

image

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:

image

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>
  15.         
  16.     </TreeView>
  17. </StackPanel>

It looks like this at runtime:

image

Conclusion

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

  1. Rich Wunderlich says:

    Is there any way to duplicate the features of the ExpressionHandle / CurrencyManagerHandle combination when using BindableViewModels?

    Things I Do
    1) Get the list from an expression handle
    2) Get the current Element from a currency manager handle
    3) Sync the list by manipulating the SelectedIndex of the control bound to the currency manager handle.
    4) Get the master/Detail Interaction to work. I can render the master and the detail, but they are not hooked up. I at least need a way to get to the variables that are created by the model.

Leave a Reply

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

*