Reputation: 239
I have a problem with getting selected option from MessageDialog in Windows Phone 8.1. What I want to do is to wait for user to choose the option and then get the chosen option and process it.
I do this with:
... initializing MessageDialog object called dialog ...
answer = (int)dialog.ShowAsync().GetResults().Id
However answer
variable does not get assigned since GetResults returns immediately without waiting for user action and returns null.
I have to get result synchronously because this code is inside a property, and more importantly inside a catch block.
Upvotes: 2
Views: 273
Reputation: 21919
You need to wait for the task to complete before GetResults will have a valid result. The easy way is to use await to wait for the dialog to finish:
var cmd = await dialog.ShowAsync();
answer = (int)cmd.Id;
You can't call an async function in a property and you can't block the UI thread to make the MessageDialog synchronous.
Instead return a stub answer and call another function to get the async result. When the result is available at the property and fire a change notification.
Upvotes: 4