Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Return value from PushModalAsync

$
0
0

I have a few pages that I'd like to call like functions. As in, I'd like to show the page modally, then do something with a result.

Because awaiting PushModalAsync doesn't actually block until popped, i'm using messagecenter to subscript for the result. It seems kinda clunky. Is there a more elegant way to do this?

        // what I think I have to do:
        async Task TakePicture()
        {
            MessagingCenter.Subscribe<CameraPageViewModel, ImageSource>(this, "CameraImage", async (sender, imageSource) =>
            {
                ImageSource = imageSource;
            });
            await ViewModelNavigation.PushModalAsync(new CameraPageViewModel()); // This returns right away
        }

        // what I wish I could do:
        async Task TakePicture()
        {
            var cameraPage = new CameraPageViewModel();
            await ViewModelNavigation.PushModalAsync(cameraPage); // In my imagination, this blocks until Popped
            ImageSource = cameraPage.Image;
        }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>