Herald.Common.NavigationHelper.OnNavigatedTo C# (CSharp) Method

OnNavigatedTo() public method

即将在 Frame 中显示此页时调用。 此方法调用 LoadState,应在此处放置所有 导航和进程生命周期管理逻辑。
public OnNavigatedTo ( NavigationEventArgs e ) : void
e Windows.UI.Xaml.Navigation.NavigationEventArgs 描述如何访问此页的事件数据。 Parameter /// 属性提供要显示的组。
return void
        public void OnNavigatedTo(NavigationEventArgs e)
        {
            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
            this._pageKey = "Page-" + this.Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // 在向导航堆栈添加新页时清除向前导航的
                // 现有状态
                var nextPageKey = this._pageKey;
                int nextPageIndex = this.Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                // 将导航参数传递给新页
                if (this.LoadState != null)
                {
                    this.LoadState(this, new LoadStateEventArgs(e.Parameter, null));
                }
            }
            else
            {
                // 通过将相同策略用于加载挂起状态并从缓存重新创建
                // 放弃的页,将导航参数和保留页状态传递
                // 给页
                if (this.LoadState != null)
                {
                    this.LoadState(this, new LoadStateEventArgs(e.Parameter, (Dictionary<String, Object>)frameState[this._pageKey]));
                }
            }
        }