I've done something similar with the ShowWindow
method from the WindowManager
, the ShowDialog
method should work in the same way when you're passing a ViewModel
(which I'm assuming you're doing in this case).
It's worth reading this page in the documentation for a more complete explanation, but essentially a Screen
has a CanClose
method, which you can override with custom behaviour.
CanClose – The default implementation always allows closing. Override this method to add custom guard logic.
So, within the ViewModel
class that you're passing to ShowDialog
, you could do something like:
public override void CanClose(Action<bool> callback)
{
bool canClose = false;
// if (yourConditionHere)
canClose = true;
callback(closeDialog);
}
Where canClose
could just as easily be a private field updated elsewhere in the class.