I have an observable that I use to display a confirmation dialog, roughly the signature:
IObservable<DialogResult> ShowDialog(string title, string message);
This shows the user a dialog with a yes / no combination.
In my main window, I access the closing event as such:
this.Events().Closing.[Do something here]
I want to be able to:
- Show confirmation dialog when closing observable
- Set the
CancelEventArgs.Cancel property to true if the user clicks the No button.
I tried a direct subscription:
this.Events().Closing.Subscribe(e => { var res = Dialogs.ShowDialog("Close?", "Really Close?").Wait(); e.Cancel = res == DialogResult.Ok; });
But this freezes due to the Wait() call, I also tried the asynchronous option:
this.Events().Closing.Subscribe(async e => { var res = await Dialogs.ShowDialog("Close?", "Really Close?"); e.Cancel = res == DialogResult.Ok; });
This is not good, because he returns immediately.
What I really want to do is something like:
this.Events().Closing.ThenDo(_ => Dialogs.ShowDialog("Close?", "Really Close?")) .Subscribe((cancelEventArgs, dialogResult) => { cancelEventArgs.Cancel == dialogResult == DialogResult.Ok; });
But this does not exist, I know that the key here is how I combine the two observables, but I have no idea how to do this, and the documentation is a little illuminated with practical examples.