CSLA 4.0 - Binding ViewModel<T> properties with Main ToolBar

CSLA 4.0 - Binding ViewModel<T> properties with Main ToolBar

Old forum URL: forums.lhotka.net/forums/t/9579.aspx


HK.Lee posted on Monday, September 27, 2010

Hi All,

Let's say 1 view acts just as layout container with toolbar and can contain other kind of views. Imagine layout view as outlookbar style view which has panelbar menus in right side and CRUD button toolbar on top side.  Whenever right menu clicked, each view opened in left tabbed region,but each view has no CRUD button.

On CAB/SCSF days, I had a base presenter interfaced with state proeprties and related method such as ViewModel does , then layout view's presenter or controller  can transfer command to related view's presenter without knowing each type as followings ;

IView activeView = myLeftRegion.GetActiveView();  

 IPresenter presenter = activeView.Presenter;

presenter.Save();

 and toolbar button enability also sticked with presenter's CanXXX state.

However in ViewModelBase<T>, it already  has all necessary method and properties, that is, if I can grab which ViewModelBase<T> is now active view's one then everything looks fine. So I  created layout viewmodel acting as a controller and  inherited from DependancyObject. However I am stucked how to declare a property which can hold active view's viewmodel.

Is there a way to declare ViewModel<T>  as followings such as MVVM 4.0 SlDemo does ?

 public class EmployeeItemViewModel: DependencyObject
  {
    public static readonly DependencyProperty ModelProperty =
        DependencyProperty.Register("Model", typeof(Library.EmployeeEdit), typeof(EmployeeItemViewModel), null);

    public Library.EmployeeEdit Model
    {
      get { return (Library.EmployeeEdit)GetValue(ModelProperty); }
      set { SetValue(ModelProperty, value); }
    }

 Or Should I follow old way creating specific interface nearly same with ViewModelBase ?                                 

Any advice would be appreciated. Thank you in advance.

HK.Lee

RockfordLhotka replied on Thursday, September 30, 2010

I haven't tried this, so I don't have a firm answer.

Data binding ignores interfaces, and uses reflection against the target object. So for data binding it really won't matter if your property uses an interface type or a concrete type or even an abstract type. At runtime data binding will use reflection to get/set any property values you use in a binding expression.

Which means that you should be able to make your property be of type object or DependencyObject and it should work.

HK.Lee replied on Friday, October 01, 2010

Thank you, Rocky.

I created interface nearly same with ViewModelBase<T>'s CanXXX properties and events as did before and attached it in my subclassed viewmodel base class. Now outside layoutview can configure which viewmodel he should handles and get CanXXX values.

RGDS

HK.Lee 

Copyright (c) Marimer LLC