I'm in the process of creating a BaseViewModel for my WPF projects, which is derived from DynamicObject, and I'm not really sure how to handle property changes to entities 'related' to the main entity (Navigation Properties of the main entity in the viewmodel).

For example:

VM:

 public class CustomerCRUDViewModel: BaseEntityViewModel<Customer>
    {
        ...
    }

This would be the VM for the Customer CRUD, for example. and the Customer entity for example has a navigation property called Address (an entity of type Address).

Now, the problem is, when binding the view to a property inside Address, changes are not reported to the VM, but to the entity directly, and therefore any behavior defined in the VM level is not triggered.

I know the explanation may not be clear enough, I just don't know how to explain myself better with my poor english.

My question is: how would the generic DynamicObject-based VM handle the scenario where I need to define behavior for properties no part of the main entity?

有帮助吗?

解决方案

I Finally Resolved this by Wrapping Navigation Properties with cached instances of BaseViewModels in the System.Dynamic.DynamicObject.TryGetMember 'getter' method. Not sure it was the most performant solution though, I can always strongly type my "Navigation view Models" in the derived entity view models.

其他提示

If your model - in this case Customer - implements the INotifyPropertyChanged interface, the viewMoodel could register to the Models PropertyChanged Event. This way the ViewModel gets informed about any property change taking place and could react accordingly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top