/// <summary>
        /// Invoked when this page will no longer be displayed in a Frame.
        /// This method calls <see cref="SaveState"/>, where all page specific
        /// navigation and process lifetime management logic should be placed.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property provides the group to be displayed.</param>
        public void OnNavigatedFrom(NavigationEventArgs e)
        {
            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
            var pageState  = new Dictionary <String, Object>();

            if (this.SaveState != null)
            {
                this.SaveState(this, new SaveStateEventArgs(pageState));
            }
            frameState[_pageKey] = pageState;
        }
예제 #2
0
 /// <summary>
 /// Invoked when this page will no longer be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property provides the group to be displayed.</param>
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     try
     {
         var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
         var pageState  = new Dictionary <string, object>();
         this.SaveState(e, pageState);
         frameState[_pageKey] = pageState;
     }
     catch (Exception ex)
     {
     }
 }
예제 #3
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
            var pageState  = new Dictionary <String, Object>();

            if (this.SaveState != null)
            {
                this.SaveState(this, new SaveStateEventArgs(pageState));
            }
            frameState[_pageKey] = pageState;

            currentView.BackRequested -= SystemNavigationManager_BackRequested;
        }
예제 #4
0
        private void CurrentGalleryPage_Loaded(object sender, RoutedEventArgs e)
        {
            var currentState = GetCurrentState("WidthStates");

            if (currentState == Width560Height0 || currentState == Width700)
            {
                // Left
                isLeft = true;
            }
            else
            {
                // Bottom
                isLeft = false;
            }

            UpdateDetailPanelState(true);

            try
            {
                // Jump to the page item if this is a back button action
                if (this.Frame.CanGoForward)
                {
                    var frameState         = SuspensionManager.SessionStateForFrame(this.Frame);
                    var lastPageParameters = frameState["Page-" + (this.Frame.BackStackDepth + 1)] as IDictionary <string, object>;
                    var index = (int)lastPageParameters["Page"];

                    // Scroll into the index of last opened page
                    ItemsWrapPanel.ScrollIntoView((ItemsWrapPanel.ItemsSource as IList)[index], ScrollIntoViewAlignment.Default);

                    ItemsWrapPanel.UpdateLayout();

                    // Start the animation
                    ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("ThumbImage");
                    if (animation != null)
                    {
                        if (ItemsWrapPanel.ContainerFromIndex(index) is ContentControl container)
                        {
                            var root  = (FrameworkElement)container.ContentTemplateRoot;
                            var image = (UIElement)root.FindName("ThumbImage");
                            animation.TryStart(image);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #5
0
        protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);

            this._pageKey = "Page-" + this.Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page to the
                // navigation stack
                var nextPageKey   = this._pageKey;
                int nextPageIndex = this.Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                // Pass the navigation parameter to the new page
                if (this.LoadState != null)
                {
                    this.LoadState(this, new LoadStateEventArgs(e.Parameter, null));
                }
            }
            else
            {
                // Pass the navigation parameter and preserved page state to the page, using
                // the same strategy for loading suspended state and recreating pages discarded
                // from cache
                if (this.LoadState != null)
                {
                    this.LoadState(this, new LoadStateEventArgs(e.Parameter, (Dictionary <String, Object>)frameState[this._pageKey]));
                }
            }


            currentView = SystemNavigationManager.GetForCurrentView();

            if (!ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                currentView.AppViewBackButtonVisibility = this.Frame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
            }


            currentView.BackRequested += SystemNavigationManager_BackRequested;
        }
예제 #6
0
        /// <summary>
        /// Handles the page serializing.
        /// </summary>
        /// <param name="navigable">The navigator view model.</param>
        /// <param name="e">The <see cref="Windows.UI.Xaml.Navigation.NavigationEventArgs" /> instance
        /// containing the event data.</param>
        private Task HandleSerializing(INavigable navigable)
        {
            var tombstone = navigable as ITombstone;

            if (tombstone != null)
            {
                var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
                var pageState  = new Dictionary <String, Object>();

                return(tombstone.OnSerializingAsync(pageState).ContinueWith(delegate
                {
                    frameState[this.pageKey] = pageState;
                }));
            }

            return(Task.CompletedTask);
        }
예제 #7
0
        protected override async void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            this.IsInView = false;

            // User left the app, wire up the resuming event in case they come back and we can restore any custom state necessary
            if (e.NavigationMode == NavigationMode.Forward)
            {
                Windows.UI.Xaml.Application.Current.Resuming += Application_Resuming;
            }

            try
            {
                // Remove the view model instance from the frame's datacontext
                this.Frame.DataContext = null;

                PlatformBase.CurrentCore.Logger.Log(LogLevels.Information, "OnNavigatedFrom: {0}\t Mode: {1}", e.SourcePageType.Name, e.NavigationMode);

                // Intialize page state for this page within the current frame
                var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
                var pageState  = new Dictionary <string, object>();

                // Wrapper object for all the navigated from event data and session state
                var args = new SaveStateEventArgs(e, pageState);

                // Pass navigation event data on to the ViewModel
                if (this.ViewModel != null)
                {
                    await this.ViewModel.SaveStateAsync(args);
                }

                // Pass navigation event data back to the page so that it has a chance to do any custom logic with access to the page state dictionary.
                await this.OnSaveStateAsync(args);

                // Save session state for the page
                frameState[_pageKey] = pageState;

                this.TeardownInterstitialAds();
            }
            catch (Exception ex)
            {
                PlatformBase.CurrentCore.Logger.LogError(ex, "Error during {0}.OnNavigatedFrom: {1} Parameter: {2}", e.SourcePageType.Name, e.NavigationMode, e.Parameter);
                throw ex;
            }
        }
예제 #8
0
        /// <summary>
        /// Navigation To
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Frame_Navigated(object sender, NavigationEventArgs e)
        {
            var naviArgs = new NavigationArgs
            {
                Content        = e.Content,
                NavigationMode =
                    (Models.NavigationMode)Enum.Parse(typeof(Models.NavigationMode), e.NavigationMode.ToString()),
                Parameter = e.Parameter,
                Uri       = e.Uri
            };

            //프레임의 세션 스테이트 값 복구
            var frameState = SuspensionManager.SessionStateForFrame(_frame);
            var pageKey    = PAGE + _frame.BackStackDepth;

            if (naviArgs.NavigationMode == Models.NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page to the
                // navigation stack
                var nextPageKey   = pageKey;
                var nextPageIndex = _frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = PAGE + nextPageIndex;
                }
                _frameSessionState  = new Dictionary <string, object>();
                frameState[pageKey] = _frameSessionState;
            }
            else
            {
                _frameSessionState = (Dictionary <String, Object>)frameState[pageKey];
            }

            if (StaticFunctions.BaseContext != null)
            {
                StaticFunctions.InvokeIfRequiredAsync(StaticFunctions.BaseContext,
                                                      para => _eventAggregator.GetEvent <NavigatedEvent>().Publish(naviArgs), null);
            }
            else
            {
                _eventAggregator.GetEvent <NavigatedEvent>().Publish(naviArgs);
            }
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property provides the group to be displayed.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Returning to a cached page through navigation shouldn't trigger state loading
            if (this._pageKey != null)
            {
                return;
            }

            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);

            this._pageKey = "Page-" + this.Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page to the
                // navigation stack
                var nextPageKey   = this._pageKey;
                int nextPageIndex = this.Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                // Pass the navigation parameter to the new page
                this.LoadState(e.Parameter, null);
            }
            else
            {
                // Pass the navigation parameter and preserved page state to the page, using
                // the same strategy for loading suspended state and recreating pages discarded
                // from cache
                this.LoadState(e.Parameter, (Dictionary <String, Object>)frameState[this._pageKey]);
            }

            // activate...
            var model = this.GetModel();

            if (model != null)
            {
                model.Activated();
            }
        }
예제 #10
0
        /// <summary>
        /// 恢复数据
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == NavigationMode.New)
            {
            }
            else
            {
                var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
                var _pageKey   = "Page-" + this.GetType().ToString();

                var data = (Dictionary <String, Object>)frameState[_pageKey];
                if (data != null && data.ContainsKey(nameof(txtInput)))
                {
                    txtInput.Text = data[nameof(txtInput)].ToString();
                }
            }
        }
예제 #11
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // Rstore GridView's scroll position.
            gridScrollViewer = FindVisualChild <ScrollViewer>(CustomerGridView);
            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);

            if (frameState.Count > 0)
            {
                Dictionary <String, Object> pos;
                if (frameState.ContainsKey("Page-" + (Frame.BackStackDepth - 2)))
                {
                    pos = frameState["Page-" + (Frame.BackStackDepth - 2)] as Dictionary <String, Object>;
                    if (pos.ContainsKey("ScrollPosition"))
                    {
                        gridScrollViewer.ChangeView(0.0f, (double)pos["ScrollPosition"], 1.0f);
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Handles the page deserializing.
        /// </summary>
        /// <param name="navigable">The navigator view model.</param>
        private bool HandleDeserializing(INavigable navigable, NavigationEventArgs e, Task navigatedTask)
        {
            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);

            this.pageKey = "Page-" + this.Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page to the navigation stack
                var nextPageKey   = this.pageKey;
                int nextPageIndex = this.Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }
            }
            else
            {
                var tombstone = navigable as ITombstone;
                if (tombstone != null)
                {
                    // Pass the navigation parameter and preserved page state to the page, using the same strategy
                    // for loading suspended state and recreating pages discarded from cache
                    var state    = (Dictionary <string, object>)frameState[this.pageKey];
                    var hasState = state.Any();

                    if (hasState)
                    {
                        RunAfter(navigatedTask, () => tombstone.OnDeserializingAsync(state));
                    }

                    return(hasState);
                }
            }

            // New page, no state, or no support for managing state
            return(false);
        }
예제 #13
0
        /// <summary>
        ///     Invoked when this page is about to be displayed in a Frame.
        ///     This method calls <see cref="LoadState" />, where all page specific
        ///     navigation and process lifetime management logic should be placed.
        /// </summary>
        /// <param name="e">
        ///     Event data that describes how this page was reached.  The Parameter
        ///     property provides the group to be displayed.
        /// </param>
        public void OnNavigatedTo(NavigationEventArgs e)
        {
            var frameState = SuspensionManager.SessionStateForFrame(Frame);

            _pageKey = "Page-" + Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page to the
                // navigation stack
                var nextPageKey   = _pageKey;
                var nextPageIndex = Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                // Pass the navigation parameter to the new page
                if (LoadState != null)
                {
                    LoadState(this, new LoadStateEventArgs(e.Parameter, null));
                }
            }
            else
            {
                // Pass the navigation parameter and preserved page state to the page, using
                // the same strategy for loading suspended state and recreating pages discarded
                // from cache
                if (LoadState != null)
                {
                    LoadState(this,
                              new LoadStateEventArgs(e.Parameter, (Dictionary <string, object>)frameState[_pageKey]));
                }
            }
        }
예제 #14
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Jump to the page item if this is a back button action
                if (this.Frame.CanGoForward)
                {
                    var frameState         = SuspensionManager.SessionStateForFrame(this.Frame);
                    var lastPageParameters = frameState["Page-" + (this.Frame.BackStackDepth + 1)] as IDictionary <string, object>;
                    var index  = (int)lastPageParameters["Index"];
                    var postId = (int)lastPageParameters["PostId"];


                    if (this.HomeViewModel.SelectedViewIndex == 0)
                    {
                        // Pre-fall creator has different image loading order
                        // unable to share same connected animation code without breaking the UI
                        if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                        {
                            var post = FeatureView.FeatureViewModel.TopToday.First(o => o.Id == postId);
                            if (post != null && FeatureView.FeatureViewModel.TopToday.IndexOf(post) != -1)
                            {
                                // Start the animation
                                ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("PreviewImage");
                                if (animation != null)
                                {
                                    FeatureView.UpdateLayout();
                                    animation.TryStart(this.FeatureView.GetTopTodayButton(FeatureView.FeatureViewModel.TopToday.IndexOf(post)));
                                }
                            }
                        }
                    }
                    else if (this.HomeViewModel.SelectedViewIndex == 1 || this.HomeViewModel.SelectedViewIndex == 2)
                    {
                        JustifiedWrapPanel panel = null;
                        if (this.HomeViewModel.SelectedViewIndex == 1)
                        {
                            // Navigating back from a search result image
                            panel = BrowsePanel;
                        }
                        else if (this.HomeViewModel.SelectedViewIndex == 2)
                        {
                            // Navigating back from a favorite image
                            panel = FavoritePanel;
                        }

                        // Scroll into the index of last opened page
                        panel.ScrollIntoView((panel.ItemsSource as IList)[index], ScrollIntoViewAlignment.Default);
                        panel.UpdateLayout();



                        // Pre-fall creator has different image loading order
                        // unable to share same connected animation code without breaking the UI
                        if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                        {
                            // Start the animation
                            ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("PreviewImage");
                            if (animation != null)
                            {
                                if (panel.ContainerFromIndex(index) is ContentControl container)
                                {
                                    var root  = (FrameworkElement)container.ContentTemplateRoot;
                                    var image = (UIElement)root.FindName("PreviewImage");
                                    animation.TryStart(image);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #15
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.IsInView = true;

            try
            {
                // Set the datacontext of the frame so that it can appropriately show the busy panel or not when a view model requests it
                this.Frame.DataContext = this.ViewModel;

                Platform.Current.Logger.Log(LogLevels.Warning, "OnNavigatedTo: {0}\t Mode: {1}\t Parameter: {2}", e.SourcePageType.Name, e.NavigationMode, e.Parameter);

                // Chck for data in session state
                Dictionary <string, Object> dic = null;
                var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
                _pageKey = "Page-" + this.Frame.BackStackDepth;
                if (e.NavigationMode == NavigationMode.New)
                {
                    // Clear existing state for forward navigation when adding a new page to the
                    // navigation stack
                    var nextPageKey   = _pageKey;
                    int nextPageIndex = this.Frame.BackStackDepth;
                    while (frameState.Remove(nextPageKey))
                    {
                        nextPageIndex++;
                        nextPageKey = "Page-" + nextPageIndex;
                    }

                    // Pass the navigation parameter to the new page
                    dic = new Dictionary <string, object>();
                }
                else
                {
                    // Pass the navigation parameter and preserved page state to the page, using
                    // the same strategy for loading suspended state and recreating pages discarded
                    // from cache
                    if (frameState.ContainsKey(_pageKey))
                    {
                        dic = (Dictionary <string, object>)frameState[_pageKey];
                    }
                    else
                    {
                        dic = new Dictionary <string, object>();
                    }
                }

                // Wrapper object for all the navigated to event data and session state
                var args = new LoadStateEventArgs(e, dic, _isInitialized);

                // Pass navigation event data back to the page so that it has a chance to do any custom logic with access to the page state dictionary.
                await this.OnLoadStateAsync(args);

                // Pass navigation event data on to the ViewModel
                if (this.ViewModel != null)
                {
                    await this.ViewModel.LoadStateAsync(this, args);
                }
            }
            catch (Exception ex)
            {
                Platform.Current.Logger.LogError(ex, "Error during {0}.OnNavigatedTo: {1} Parameter: {2}", e.SourcePageType.Name, e.NavigationMode, e.Parameter);
                throw ex;
            }
            finally
            {
                _isInitialized = true;
            }
        }