Ejemplo n.º 1
0
        void InvokeOnNavigatedFrom(object item, NavigationContext navigationContext)
        {
            var navigationAwareItem = item as INavigationAware;

            if (navigationAwareItem != null)
            {
                navigationAwareItem.OnNavigatedFrom(navigationContext);
            }

            var frameworkElement = item as FrameworkElement;

            if (frameworkElement != null)
            {
                INavigationAware navigationAwareDataContext = frameworkElement.DataContext as INavigationAware;
                if (navigationAwareDataContext != null)
                {
                    navigationAwareDataContext.OnNavigatedFrom(navigationContext);
                }
                if (frameworkElement != null)
                {
                    var        viewModel     = frameworkElement.DataContext;
                    Type       viewModelType = viewModel.GetType();
                    MethodInfo methodInfo    = viewModelType.GetMethod("DisposeEvents");
                    if (methodInfo != null)
                    {
                        methodInfo.Invoke(viewModel, null);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            INavigationAware vm = DataContext as INavigationAware;

            if (vm != null)
            {
                vm.OnNavigatedFrom(e.Parameter, e.NavigationMode);
            }

            base.OnNavigatedFrom(e);
        }
        private void ExecuteSearch(string phrase)
        {
            var searchBar = SearchBarService.Current;

            if (searchBar != null)
            {
                UriQuery query = new UriQuery(searchBar.Parameters.ToString());
                query.Add(SearchBar.ValueParameter, phrase);
                query.Add(SearchBar.IsFromSearchBarParameter, "true");

                IRegion viewRegion = RegionManager.Regions[AppRegions.ViewRegion];
                IRegionNavigationService navigation = viewRegion.NavigationService;

                if (navigation.Journal.CurrentEntry != null)
                {
                    if (navigation.Journal.CurrentEntry.Uri.OriginalString.StartsWith(searchBar.NavigationUri.OriginalString))
                    {
                        INavigationAware navAware = null;
                        var activeView            = viewRegion.ActiveViews.FirstOrDefault();

                        if (activeView is INavigationAware)
                        {
                            navAware = activeView as INavigationAware;
                        }
                        else
                        {
                            FrameworkElement element = activeView as FrameworkElement;

                            if (element != null && element.DataContext is INavigationAware)
                            {
                                navAware = element.DataContext as INavigationAware;
                            }
                        }

                        if (navAware != null)
                        {
                            navAware.OnNavigatedFrom(new NavigationContext(navigation,
                                                                           navigation.Journal.CurrentEntry.Uri));
                            navAware.OnNavigatedTo(new NavigationContext(navigation,
                                                                         new Uri(
                                                                             searchBar.NavigationUri.ToString() + query,
                                                                             UriKind.RelativeOrAbsolute)));
                            return;
                        }
                    }
                }

                RegionManager.RequestNavigate(AppRegions.ViewRegion, searchBar.NavigationUri.ToString() + query);
            }
        }
Ejemplo n.º 4
0
        void InvokeOnNavigatedFrom(object item, NavigationContext navigationContext)
        {
            var navigationAwareItem = item as INavigationAware;

            if (navigationAwareItem != null)
            {
                navigationAwareItem.OnNavigatedFrom(navigationContext);
            }

            var frameworkElement = item as FrameworkElement;

            if (frameworkElement != null)
            {
                INavigationAware navigationAwareDataContext = frameworkElement.DataContext as INavigationAware;
                navigationAwareDataContext?.OnNavigatedFrom(navigationContext);
            }
        }
Ejemplo n.º 5
0
        private async Task <NavigationResult> HandleViewModelNavigation(INavigationAware fromPageVM, INavigationAware toPageVM, INavigationParameters parameters)
        {
            if (fromPageVM != null)
            {
                try
                {
                    fromPageVM.OnNavigatedFrom(parameters);
                }
                catch (Exception ex)
                {
                    return(new NavigationResult()
                    {
                        IsSuccess = false, Exception = ex
                    });
                }
            }


            if (toPageVM != null)
            {
                try
                {
                    toPageVM.OnNavigatingTo(parameters);
                    toPageVM.OnNavigatedTo(parameters);
                    await toPageVM.OnNavigatedToAsync(parameters);
                }
                catch (Exception ex)
                {
                    return(new NavigationResult()
                    {
                        IsSuccess = false, Exception = ex
                    });
                }
            }

            return(new NavigationResult()
            {
                IsSuccess = true
            });
        }
Ejemplo n.º 6
0
        protected override void OnPause()
        {
            base.OnPause();

            _navigationAwareVm?.OnNavigatedFrom();
        }