Search code examples
c#win-universal-app

How to make modal Window in UWP and return value when it is closed


I need to implement some functionality in a second Window in UWP.

So I want to do following

  1. Start new Window in a Modal state so parent Window cannot be acceced.
  2. On closed event return value to the parent Window.

I use following code to create a new Window please help me to archive these points

private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var switchToView = true;

            var newView = CoreApplication.CreateNewView();
            int newViewId = 0;
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame = new Frame();
                frame.Navigate(typeof(MyCam), null);
                Window.Current.Content = frame;

                newViewId = ApplicationView.GetForCurrentView().Id;
            });
            var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
            if (switchToView && viewShown)
            {
                // Switch to new view
                await ApplicationViewSwitcher.SwitchAsync(newViewId);
            }            
        }

Solution

  • I found nice solution here https://github.com/bkaankose/UWPModalDialogHelper

    It is about to use Prism.Core Nuget package to simulate fullscreen popup with custom UserControl.