Why is ContentDialog and Prism Navigation blowing up my UWP app?

Viewed 1401

I am showing a content dialog on one of my sessionstateaware pages, I close the dialog fine and can reopen another on the same page as many times as I want. When I navigate away and come back and try to reopen my dialog, it blows up with this error:

WinRT information: Only a single ContentDialog can be open at any time. Additional information: An async operation was not properly started.

I have tried numerous things, but it seems whenever I navigate away and come back, somehow the reference to the control is lost and another gets created?

Here is a little snippet of the problem area:

if(asyncCommand != null)
asyncCommand.Cancel();

var result = new ContentDialogResult();
if (CanOpenNewDialog)
{

    CanOpenNewDialog = false;
    MyContentDialog.Title = "Homebuyer Options - " + apt.Customer1FullName;
    asyncCommand = MyContentDialog.ShowAsync();

    result = await asyncCommand.AsTask();
}
3 Answers
Related