简体   繁体   中英

Windows Phone 8.1 MessageDialog results

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM