5

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?

H.B.
  • 166,899
  • 29
  • 327
  • 400
WPFKK
  • 1,419
  • 3
  • 20
  • 42
  • I did something similar, but instead I allowed to navigate to different parents views while a child was open, and even to different modules. Then if the user try to close the app. instead I would navigate back to the opened view(s) if any. But I haven't found a way to tell child that a parent is navigating. Would something like this make sense? – adminSoftDK Jul 20 '16 at 13:28

1 Answers1

0

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.

mcwyrm
  • 1,571
  • 1
  • 15
  • 27