Exemple #1
0
        async private void gotoMainPage_Click(object sender, RoutedEventArgs e)
        {
            // Switch to the main view without explicitly requesting
            // that this view be hidden.
            thisViewControl.StartViewInUse();
            await ApplicationViewSwitcher.SwitchAsync(mainViewId);

            thisViewControl.StopViewInUse();
        }
        async private void showView_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Prevent the view from closing while switching to it
                ViewLifetimeController selectedView = viewList.SelectedItem as ViewLifetimeController;
                selectedView.StartViewInUse();

                // Show the previously created secondary view, using the size
                // preferences the user specified.
                bool isViewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                    selectedView.Id, ViewSizePreference.Default,
                    ApplicationView.GetForCurrentView().Id, ViewSizePreference.Default);

                if (isViewShown)
                {
                    // If we succefully showed the view, make sure we update our internal state
                    // to reflect that the view is no longer consolidated.
                    selectedView.Consolidated = false;
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.MULTIVIEW_SHOW_VIEW_SUCCESS, selectedView.Title));
                }
                else
                {
                    // The window wasn't actually shown, so release the reference to it.
                    // This might trigger the window to be destroyed.
                    status.Log(LocalizableStrings.MULTIVIEW_SHOW_VIEW_FAIL);
                }

                // Signal that switching has completed and let the view close
                selectedView.StopViewInUse();
            }
            catch (InvalidOperationException ex)
            {
                // The view could be in the process of closing, and
                // this thread just hasn't updated. As part of being closed,
                // this thread will be informed to clean up its list of
                // views (see SecondaryViewPage.xaml.cs).
                Debug.WriteLine("MultiViewPage.showView_Click: " + ex.ToString());
                status.Log(ex.Message);
            }
        }