Reputation: 1477
I have Nested regions
a. ParentView/ParentRegion/ParentViewModel
b. Child1View/ChildRegion/Child1ViewModel
b. Child2View/ChildRegion/Child2ViewModel
b. Child3View/ChildRegion/Child3ViewModel
CASE 1: I need to have an event or trigger when Parent is navigating from which happens in ParentViewModel. But Parent is not aware of Child(s) types so If any Child is invalid I wish to prompt user to save or cancel. How to achieve this?
CASE 2:My ChildRegion is like navigating between siblings even then i need to have an event fired when Navigating From between the children and should be able to stop navigation if the current view is not valid or incomplete
My trials: I did INavigationAware on all Parent and Child but When parent navigates child does not trigger and i have no reference to child in parent navigate from.
How do i fix this scenario?
Upvotes: 5
Views: 442
Reputation: 1693
You will want to use some version of the observer pattern here. Each child region should subscribe to an event which is triggered by the parent region in its INavigationAware.NavigateFrom
method. Another event (or the same event, if separate functionality is not required) could be triggered by each child in its implementation of the same
Alternately, you could consider using a CompositeCommand instead of an event.
Upvotes: 0