示例#1
0
        private async void InitializeMainPage(ApplicationExecutionState previousExecutionState, String arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                mainDispatcher = Window.Current.Dispatcher;
                mainViewId     = ApplicationView.GetForCurrentView().Id;
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null || !String.IsNullOrEmpty(arguments))
            {
                // This is encountered on the first launch of the app. Make sure to call
                // DisableShowingMainViewOnActivation before the first call to Window::Activate

                var shouldDisable = Windows.Storage.ApplicationData.Current.LocalSettings.Values[App.DISABLE_MAIN_VIEW_KEY];
                if (shouldDisable != null && (bool)shouldDisable)
                {
                    ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
                }

                // When the navigation stack isn't restored or there are launch arguments
                // indicating an alternate launch (e.g.: via toast or secondary tile),
                // navigate to the appropriate page, configuring the new page by passing required
                // information as a navigation parameter
                if (!rootFrame.Navigate(typeof(MainPage), arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
示例#2
0
        private async void btnShow_Click(object sender, RoutedEventArgs e)
        {
            /*
             * CoreApplication.CreateNewView() - 创建一个新的 SecondaryView(只是新建一个 SecondaryView 实例,并不会显示出来)
             */
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                _secondaryViewHelper       = SecondaryViewHelper.CreateForCurrentView();
                _secondaryViewHelper.Title = "i am secondary view";

                _secondaryViewHelper.StartViewInUse();

                var frame = new Frame();
                frame.Navigate(typeof(SecondaryViewPage), _secondaryViewHelper);
                Window.Current.Content = frame;
                Window.Current.Activate();

                // 这里通过 ApplicationView.GetForCurrentView() 获取到的是新开窗口的 ApplicationView 对象
                ApplicationView secondaryView = ApplicationView.GetForCurrentView();
            });

            try
            {
                _secondaryViewHelper.StartViewInUse();

                /*
                 * ApplicationViewSwitcher.TryShowAsStandaloneAsync() - 在当前窗口的相邻位置显示另一个窗口
                 */
                ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
                var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync
                                (
                    _secondaryViewHelper.Id,                // 需要显示的 SecondaryView 的窗口 id
                    ViewSizePreference.Default,             // 需要显示的 SecondaryView 的尺寸首选项(经测试,此参数无效)
                    ApplicationView.GetForCurrentView().Id, // 调用者的窗口 id
                    ViewSizePreference.Default              // 调用者的尺寸首选项(经测试,此参数无效)
                                );

                if (!viewShown)
                {
                    lblMsg.Text = "显示 SecondaryView 失败";
                }

                _secondaryViewHelper.StopViewInUse();
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.ToString();
            }
        }
示例#3
0
    /// <summary>
    /// Visually replaces the current view with this view.
    /// </summary>
    /// <param name="fromView">
    /// The view you are switching from.
    /// </param>
    /// <param name="options">
    /// Options for the display transition behaviors.
    /// </param>
    /// <returns>
    /// A <see cref="Task"/> that represents the operation.
    /// </returns>
    public async Task SwitchAndConsolidateAsync(AppViewInfo fromView, ApplicationViewSwitchingOptions options)
    {
        // From view MUST be passed
        if (fromView == null)
        {
            throw new ArgumentNullException(nameof(fromView));
        }

        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
        {
            ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
            await ApplicationViewSwitcher.SwitchAsync(this.view.Id, fromView.view.Id, options);
            await this.view.TryConsolidateAsync();
        });
    }
示例#4
0
        public static async Task TryShowNewWindowAsync(Page content, bool switchToView)
        {
            var newView   = CoreApplication.CreateNewView();
            var newViewId = 0;
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                Window.Current.Content = content;

                newViewId = ApplicationView.GetForCurrentView().Id;
            });

            ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
            var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);

            if (switchToView && viewShown)
            {
                await ApplicationViewSwitcher.SwitchAsync(newViewId);
            }
        }