Exemplo n.º 1
0
        private void NavigateToStarPage(Frame rootFrame, System.Object parameter)
        {
            //if we have already active background task, we can go strait viewing values from it
            if (BackgroundManager.IsBackgroundTaskRegistered())
            {
                if (!rootFrame.Navigate(typeof(HeartBeatPage), parameter))
                {
                    throw new Exception("Failed to create initial page");
                }

                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                if (!rootFrame.Navigate(typeof(MainPage), parameter))
                {
                    throw new Exception("Failed to create initial page");
                }

                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        private async void App_BackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                return;
            }

            if (rootFrame.SourcePageType.Equals(typeof(HeartBeatPage)))
            {
                if (BackgroundManager.IsBackgroundTaskRegistered())
                {
                    e.Handled = true;

                    //Todo, consider movcing this to be handled inside the UI, not in external popup
                    // so we are going back from HeartBeatPage and we have active background task
                    // so we need to ask whether we want to keep it or not
                    var dlg = new MessageDialog("Stop Background heartbeat monitoring ?");
                    dlg.Commands.Add(new UICommand("Yes", null, "YES"));
                    dlg.Commands.Add(new UICommand("No", null, "NO"));
                    var op = await dlg.ShowAsync();

                    if ((string)op.Id == "YES")
                    {
                        BackgroundManager.UnregisterBackgroundTask();

                        if (rootFrame.CanGoBack)
                        {   // if we started with Mainpage, we'll just  go back
                            rootFrame.GoBack();
                        }
                        else
                        {   //but if we started with Heartbeat page, we actually need to navigate to the mainpage
                            rootFrame.Navigate(typeof(MainPage));
                        }
                    }
                    else
                    {
                        // lets let the background task run, while UI goes out
                        Exit();
                    }

                    return;
                }
                else if (rootFrame.CanGoBack)
                {//this would be error situation, where we went to HeartBeatPage without active background task
                    rootFrame.GoBack();
                }
            }

            if (rootFrame.SourcePageType.Equals(typeof(MainPage)))
            {
                e.Handled = true;
                // from mainview we simply exit
                Exit();
                return;
            }

            // if we are here, we should just go back if it is possible
            if (rootFrame.CanGoBack && !e.Handled)
            {
                e.Handled = true;
                rootFrame.GoBack();
            }
        }