BaconographyWP8.MainPage.OnNavigatingFrom C# (CSharp) Method

OnNavigatingFrom() protected method

protected OnNavigatingFrom ( System.Windows.Navigation.NavigatingCancelEventArgs e ) : void
e System.Windows.Navigation.NavigatingCancelEventArgs
return void
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back && DataContext is ViewModelBase)
            {
                _viewModelContextService.PopViewModelContext(DataContext as ViewModelBase);
            }
            else if (e.NavigationMode == NavigationMode.New)
            {
                //Cleanup so we dont reposition to something old when we return
                if (pivot != null && pivot.Items != null && pivot.Items.FirstOrDefault() != null)
                {
                    var pivotItem = pivot.Items.FirstOrDefault() as PivotItem;
                    if (pivotItem != null && pivotItem.DataContext is RedditViewModel)
                    {
                        var redditViewModel = pivotItem.DataContext as RedditViewModel;
                        redditViewModel.TopVisibleLink = null;
                    }
                }
            }
            base.OnNavigatingFrom(e);
        }