I’m using Prism and my views implement IConfirmNavigationRequest in order to enable them to perform validations and cancel the navigation if required.
My problem is that I have several views which don’t use MVVM, and define DataContext = this. Doing so causes Prism to call my view’s ConfirmNavigationRequest() twice, which means I ask for the user’s response twice.
Basically what’s going on is this:
- Prism checks if the view implements
IConfirmNavigationRequestand callsConfirmNavigationRequest()on it if it does. - The user is asked whether he’d like to continue.
- The user clicks OK and
ConfirmNavigationRequest()returnstrue. - Prism checks if the viewmodel (in my case, it’s the view again) implements
IConfirmNavigationRequestand callsConfirmNavigationRequest()on it if it does. - The user is asked again whether he’d like to continue.
As you can see, Prism asks my view for confirmation twice because it queries both the view and the viewmodel.
So my question is, how can I prevent this from happening or how can I detect which call is which so I can ignore one of them? I thought about investigating the continuationCallback parameter, but I don’t like this solution so much since it’s not unlikely it’ll break in the next versions of Prism.
The best solution I got so far is the one I got from DCherubini at Prism’s forum, which suggests that I won’t set the view’s
DataContexton myUserControl, but use an inner element that will hold the view, and set theDataContextfor it instead:instead of
This should work, but it means I need to change each view individually. A solution that doesn’t require making changes to the views would be nicer.