If it answers ‘yes’, show the marketplace review task.<\/li>\n<\/ol>\nAs I like playing with tasks, I was using this code :
\n[csharp]
\n protected async override void OnNavigatedTo(NavigationEventArgs e)
\n {
\n base.OnNavigatedTo(e);
\n var mBox = new CustomMessageBox
\n {
\n Title = "Do you want to… ",
\n Message = " … click on yes ?",
\n LeftButtonContent = "Yes",
\n RightButtonContent = "No"
\n };
\n var result = await ShowAsync(mBox);
\n NavigationService.Navigate(new Uri("\/OtherPage.xaml", UriKind.RelativeOrAbsolute));
\n }<\/p>\n
public static async Task<CustomMessageBoxResult> ShowAsync(CustomMessageBox box)
\n {
\n var taskCompletionSource = new TaskCompletionSource<CustomMessageBoxResult>();
\n box.Dismissed += (a, b) => taskCompletionSource.TrySetResult(b.Result);<\/p>\n
try { box.Show(); }
\n catch (Exception exception) { taskCompletionSource.TrySetException(exception); }<\/p>\n
return await taskCompletionSource.Task;
\n }
\n[\/csharp]<\/p>\n
This code was throwing an exception. To fix it, I downloaded the source of the Windows Phone Toolkit and I saw that at the end of the dismissal animation, it was trying to access the “Popup” object which was null : BOUM !<\/p>\n
So… how did I fix it ? Simply by waiting for the popup to be unloaded instead of using directly the Dismissed event of the CustomMessageBox :
\n[csharp]
\npublic static async Task<CustomMessageBoxResult> ShowAsync(CustomMessageBox box)
\n{
\n var taskCompletionSource = new TaskCompletionSource<CustomMessageBoxResult>();
\n var result = CustomMessageBoxResult.None;<\/p>\n
\/\/Only store the result here.
\n box.Dismissed += (a, b) => result = b.Result;<\/p>\n
\/\/Use this event to set the result.
\n box.Unloaded += (_, __) => taskCompletionSource.TrySetResult(result);<\/p>\n
try { box.Show(); }
\n catch (Exception exception) { taskCompletionSource.TrySetException(exception); }<\/p>\n
return await taskCompletionSource.Task;
\n}
\n[\/csharp]<\/p>\n
I hope it will save you some time too \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"
The Windows Phone Toolkit is really useful. Yesterday, while I was updating my ConsoTracker app, I met a strange bug using the CustomMessageBox : it was raising a nullReference exception. Let’s see what was the…<\/p>\n","protected":false},"author":3,"featured_media":1385,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,4],"tags":[14,15,44,45],"_links":{"self":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/1381"}],"collection":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/comments?post=1381"}],"version-history":[{"count":8,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/1381\/revisions"}],"predecessor-version":[{"id":1390,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/1381\/revisions\/1390"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/media\/1385"}],"wp:attachment":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/media?parent=1381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/categories?post=1381"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/tags?post=1381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}