Esempio n. 1
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;
                int nextPageIndex = Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                // Pass the navigation parameter to the new page
                LoadState?.Invoke(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
                LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, (Dictionary <String, Object>)frameState[_pageKey]));
            }

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = CanGoBack() ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
        }
        /// <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 virtual void OnNavigatedTo(NavigationEventArgs e)
        {
            var frameState = GetSessionState();

            _pageKey = e.Parameter as string ?? "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
                LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, null));
            }
            else
            {
                var state = (Dictionary <string, object>)frameState[_pageKey];
                //NOTE loading state of view model.
                UwpToolkitExtensions.ApplicationStateManager.OnLoadState(Page, state, e);
                // 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
                LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, state));
            }
        }
Esempio n. 3
0
        internal Frame(IChannelOwner parent, string guid, FrameInitializer initializer) : base(parent, guid)
        {
            _channel     = new FrameChannel(guid, parent.Connection, this);
            _initializer = initializer;
            Url          = _initializer.Url;
            Name         = _initializer.Name;
            ParentFrame  = _initializer.ParentFrame;
            _loadStates  = initializer.LoadStates;

            _channel.LoadState += (sender, e) =>
            {
                lock (_loadStates)
                {
                    if (e.Add.HasValue)
                    {
                        _loadStates.Add(e.Add.Value);
                        LoadState?.Invoke(this, new LoadStateEventArgs {
                            LifecycleEvent = e.Add.Value
                        });
                    }

                    if (e.Remove.HasValue)
                    {
                        _loadStates.Remove(e.Remove.Value);
                    }
                }
            };

            _channel.Navigated += (sender, e) =>
            {
                Url  = e.Url;
                Name = e.Name;
                Navigated?.Invoke(this, e);

                if (string.IsNullOrEmpty(e.Error))
                {
                    ((Page)Page)?.OnFrameNavigated(this);
                }
            };
        }
Esempio n. 4
0
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "navigated":
                var e = serverParams?.ToObject <FrameNavigatedEventArgs>(Connection.GetDefaultJsonSerializerOptions());

                if (serverParams.Value.TryGetProperty("newDocument", out var documentElement))
                {
                    e.NewDocument = documentElement.ToObject <NavigateDocument>(Connection.GetDefaultJsonSerializerOptions());
                }

                Navigated?.Invoke(this, e);
                break;

            case "loadstate":
                LoadState?.Invoke(
                    this,
                    serverParams?.ToObject <FrameChannelLoadStateEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;
            }
        }
Esempio n. 5
0
        public void OnNavigatedTo(NavigationEventArgs e)
        {
            var frameState = SuspensionManager.SessionStateForFrame(this.Frame);

            _pageKey = "Page-" + Frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                var nextPageKey   = this._pageKey;
                int nextPageIndex = this.Frame.BackStackDepth;
                while (frameState.Remove(nextPageKey))
                {
                    nextPageIndex++;
                    nextPageKey = "Page-" + nextPageIndex;
                }

                LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, null));
            }
            else
            {
                LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, (Dictionary <String, Object>)frameState[this._pageKey]));
            }
        }