Reputation: 489
I have a scenario where I have multiple views registered in a window with one view active at a time.
I am using a CompositeCommand when the window is closing to validate the close can occur, with each view registering a command with that composite command.
The composite command works as expected, but my problem is that some of the views need to raise an interaction request to allow the user to confirm they want the window to close without fixing validation issues on those views.
To do this some of the views have interaction requests which they trigger when their command fires and then need user confirmation.
The issue that I'm having is that if the view isn't the currently active view then the interactionrequest cannot fire as either the Raised event becomes null or an exception of "This Visual is not connected to a PresentationSource" is thrown.
I have tried to implement an activation of the view that wants to raise an interaction request but because the composite command is executing synchronously the view cannot be activated before the interaction request needs to fire.
Am I going about implementing this wrong? Or is there a way to get the interaction request to not throw?
Thanks!
Upvotes: 0
Views: 803
Reputation: 2070
I would say this is one of those places where InteractionRequest is not the right tool for the job. It has an implicit assumption that it is an interaction for the currently presented view. For things like you are describing, I typically have an app level DialogService that can present some sort of dialog to the user regardless of what view is currently on screen. ViewModels or other services can inject an interface reference to that and show dialogs anytime they want to.
The implementation of that service can use InteractionRequest itself at the shell level, but then you can run into placement issues depending on how you want that dialog presented. So I'll often just have that service new up its own window as the frame for the dialog and present it with the content passed through the interface.
Hope that helps.
Upvotes: 2