Mar 9, 2012 at 8:51 AM
Edited Mar 9, 2012 at 8:58 AM
|
My UI is derived from the HelloScreens sample (simplyfied):
- ShellViewModel contains items of MasterViewModel<TEntity> : Conductor...
(Workspaces for all root entities)
(e.g. CustomerMasterViewModel : MasterViewModel<Customer>, ...) - MasterViewModel<TEntity> can open items of DetailViewModel<Customer> : Conductor...
(e.g. CustomerDetailViewModel : DetailViewModel<Customer>, ...) - Each DetailViewModel<TEntity> can have items of TabViewModel<TEntity> : Screen
- Via MEF and the 'marker' TEntity all parts (Master, Detail, Tabs) are composed automatically. Because all master and detail views are very similar, all implementations are mapped to one MasterView and one DetailView. Only the contents (master: grid, actions,
open/recent items etc.; detail: tabs, actions etc.) can vary, so that there are view models and views for all tabs. Some of the tabs show lists that where already loaded with the entity and others just use the fk of the entity to load related data.
DetailViewModel<TEntity>loads an entity and the tab base class
TabViewModel<TEntity> can access the entity:
public DetailViewModel<TEntity> ParentDetail { get; set; }
public TEntity Entity { get { return ParentDetail.Entity; } }
A tab view could now bind to the nested POCO property from above:
<TextBox x:Name="Entity_Name"/>
This would be great, but unfortunatelly INPC is not triggered this way, because my entities don't implement INPC. At the moment the related
DetailViewModel<TEntity> only uses the Refresh() method inside the setter of the Entity property and when the active tab is changed.
So the question is:
1) Do I really have to duplicate all view model properties in each tab to implement INPC or is there a better way (kepping CMs nested property bindings)?
I tried
notifypropertyweaver, but it would only help with duplicated properties that wrap the nested properties and makes dependent properties and guards a bit more complicated (e.g. CanSave would have to use CustomerName instead of Entity.Name):
public string CustomerName { get {return Entity.Name;} set {Entity.Name = value;}}
A nice solution would be a proxy that adds INPC to a POCO (perhaps in the setter), so that nested bindings like Entity_Name can trigger the change event. Has anyone done something like that yet?
2) Is there a way to apply the desired behavior by customizing or extending CM?
Just off the top of my head: When a binding to a nested property is used (Entity_Name), all changes of the control should trigger INPC of the root property (Entity) by setting Entity=Entity, so that guards and validation related to the root property can
be notified by NPCs in the setter of the root property.
Does CM have any extension points to do something like that?
|