Beispiel #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            showWindowBtn.IsEnabled = false;

            // Only ever create and show one window. If the AppWindow exists call TryShow on it to bring it to foreground.
            if (appWindow == null)
            {
                // Create a new window
                appWindow = await AppWindow.TryCreateAsync();

                // Make sure we release the reference to this window, and release XAML resources, when it's closed
                appWindow.Closed += delegate { appWindow = null; appWindowFrame.Content = null; };
                // Navigate the frame to the page we want to show in the new window
                appWindowFrame.Navigate(typeof(SecondaryAppWindowPage));
                // Attach the XAML content to our window
                ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowFrame);
            }

            // Get DisplayRegion to position our window on
            DisplayRegion secondaryDisplayRegion = GetOtherDisplayRegion(ApplicationView.GetForCurrentView().GetDisplayRegions()[0]);

            if (secondaryDisplayRegion != null)
            {
                appWindow.RequestMoveToDisplayRegion(secondaryDisplayRegion);
            }

            // If the window is not visible, show it and/or bring it to foreground
            if (!appWindow.IsVisible)
            {
                await appWindow.TryShowAsync();
            }

            showWindowBtn.IsEnabled = true;
        }