2

I was porting a modal dialog to a non-modal one.

My problem is: uiCompletedEventArgs.Result is null.

I've seen having the debug exception enabled that the following exception is thrown "DialogResult can be set only after Window is created and shown as dialog."

Here is a snippet of my code

 var viewmodel = viewModelFactory.CreateViewModel<GenericViewModel>(someIds);

       uiVisualizerService.Show(viewmodel, CompletedProc);
    }

    private async void CompletedProc(object sender, UICompletedEventArgs uiCompletedEventArgs)
    {
        if (uiCompletedEventArgs.Result.HasValue && uiCompletedEventArgs.Result.Value) //here's null
        { ... }

How can I tell if a user clicked Yes or Cancel button?

Thanks for your advice.

pizzaboy
  • 995
  • 1
  • 9
  • 20

1 Answers1

3

Unfortunately you cannot set DialogResult when you call window.Show (WPF limitation, it's only possible when using window.ShowDialog). Therefore you will need to do one of the following:

  1. Subscribe to the Canceled or Saved events of the view model to check whether it was saved or canceled
  2. Create a model that you inject into the vm that holds the state
Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32