Exemplo n.º 1
0
 /// <summary>
 /// Called when navigation is performed to a page. You can use this method to load state if it is available.
 /// </summary>
 /// <param name="e">The <see cref="NavigatedToEventArgs"/> instance containing the event data.</param>
 /// <param name="viewModelState">The state of the view model.</param>
 public virtual void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
 {
     if (viewModelState != null)
     {
         RestoreViewModel(viewModelState, this);
     }
 }
Exemplo n.º 2
0
        private void OnFrameNavigatedTo(object sender, NavigationEventArgs e)
        {
            if (_navigatedToEventHandlers.Count > 0)
            {
                var args = new NavigatedToEventArgs(e);

                foreach (var handler in _navigatedToEventHandlers)
                {
                    handler(this, args);
                }
            }
        }
Exemplo n.º 3
0
        public void OnNavigatedTo_With_RestorableStateAttribute()
        {
            var viewModelState = new Dictionary<string, object>();
            viewModelState.Add("Title", "MyMock");
            viewModelState.Add("Description", "MyDescription");

            var vm = new MockViewModelWithRestorableStateAttributes();

            NavigatedToEventArgs args = new NavigatedToEventArgs();
            args.NavigationMode = NavigationMode.Back;

            vm.OnNavigatedTo(args, viewModelState);

            Assert.AreEqual(vm.Title, viewModelState["Title"]);
            Assert.AreEqual(vm.Description, viewModelState["Description"]);
        }
Exemplo n.º 4
0
        public void OnNavigatedTo_With_No_RestorableStateAttributes()
        {
            var viewModelState = new Dictionary<string, object>();
            viewModelState.Add("Title", "MyMock");
            viewModelState.Add("Description", "MyDescription");

            var viewState = new Dictionary<string, object>();
            viewState.Add("Tests.Mocks.MockViewModelWithNoResumableStateAttributes1", viewModelState);

            var vm = new MockViewModelWithNoRestorableStateAttributes();

            NavigatedToEventArgs args = new NavigatedToEventArgs();
            args.NavigationMode = NavigationMode.Back;

            vm.OnNavigatedTo(args, viewState);

            Assert.IsNull(vm.Title);
            Assert.IsNull(vm.Description);
        }
Exemplo n.º 5
0
 public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> viewState)
 {
     this.OnNavigatedToCommand(e.Parameter, e.NavigationMode, viewState);
 }
Exemplo n.º 6
0
        public void OnNavigatedTo_With_RestorableStateCollection()
        {
            var childViewModelState = new Dictionary<string, object>();
            childViewModelState.Add("Title", "MyChildMock");
            childViewModelState.Add("Description", "MyChildDescription");

            var viewModelState = new Dictionary<string, object>();
            viewModelState.Add("Tests.Mocks.MockViewModelWithResumableStateCollection1", childViewModelState);

            var viewState = new Dictionary<string, object>();
            viewState.Add("MyEntityId", viewModelState);

            var vm = new MockViewModelWithRestorableStateCollection()
            {
                ChildViewModels = new List<BindableBase>()
                {
                    new MockViewModelWithRestorableStateAttributes
                    {
                        Title = "MyChildMock",
                        Description = "MyChildDescription"
                    }
                }
            };
            NavigatedToEventArgs args = new NavigatedToEventArgs();
            args.NavigationMode = NavigationMode.Back;

            vm.OnNavigatedTo(args, viewState);

            var childViewModel = (MockViewModelWithRestorableStateAttributes)vm.ChildViewModels.FirstOrDefault();

            Assert.AreEqual(childViewModel.Title, childViewModelState["Title"]);
            Assert.AreEqual(childViewModel.Description, childViewModelState["Description"]);
        }
Exemplo n.º 7
0
        private void OnFrameNavigatedTo(object sender, NavigationEventArgs e)
        {
            if (_navigatedToEventHandlers.Count > 0)
            {
                var args = new NavigatedToEventArgs(e);

                foreach (var handler in _navigatedToEventHandlers)
                    handler(this, args);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the Navigated event of the Frame control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="NavigatedToEventArgs"/> instance containing the event data.</param>
        private void OnFrameNavigatedTo(object sender, NavigatedToEventArgs e)
        {
            // Update the page type and parameter of the last navigation
            _sessionStateService.SessionState[LastNavigationPageKey] = _frame.Content.GetType().FullName;
            _sessionStateService.SessionState[LastNavigationParameterKey] = e.Parameter;

            NavigateToCurrentViewModel(e);
        }
Exemplo n.º 9
0
        /// <summary>
        /// This method is triggered after navigating to a view model. It is used to load the view model state that was saved previously.
        /// </summary>
        /// <param name="e">The <see cref="NavigatedToEventArgs"/> instance containing the event data.</param>
        private void NavigateToCurrentViewModel(NavigatedToEventArgs e)
        {
            var frameState = _sessionStateService.GetSessionStateForFrame(_frame);
            var viewModelKey = "ViewModel-" + _frame.BackStackDepth;

            if (e.NavigationMode == NavigationMode.New)
            {
                // Clear existing state for forward navigation when adding a new page/view model to the
                // navigation stack
                var nextViewModelKey = viewModelKey;
                int nextViewModelIndex = _frame.BackStackDepth;
                while (frameState.Remove(nextViewModelKey))
                {
                    nextViewModelIndex++;
                    nextViewModelKey = "ViewModel-" + nextViewModelIndex;
                }
            }

            var newView = _frame.Content as FrameworkElement;
            if (newView == null) return;
            var newViewModel = newView.DataContext as INavigationAware;
            if (newViewModel != null)
            {
                Dictionary<string, object> viewModelState;
                if (frameState.ContainsKey(viewModelKey))
                {
                    viewModelState = frameState[viewModelKey] as Dictionary<string, object>;
                }
                else
                {
                    viewModelState = new Dictionary<string, object>();
                }
                newViewModel.OnNavigatedTo(e, viewModelState);
                frameState[viewModelKey] = viewModelState;
            }
        }