Пример #1
0
        private void ExecuteNavigation(INavigationContext navigationContext, object[] activeViews, Action <IRegionNavigationResult> navigationCallback)
        {
            try
            {
                NotifyActiveViewsNavigatingFrom(navigationContext, activeViews);

                var view = (VisualElement)_regionNavigationContentLoader.LoadContent(Region, navigationContext);

                // Raise the navigating event just before activating the view.
                RaiseNavigating(navigationContext);

                Region.Activate(view);

                // Update the navigation journal before notifying others of navigation
                IRegionNavigationJournalEntry journalEntry = _container.Resolve <IRegionNavigationJournalEntry>();
                journalEntry.Uri        = navigationContext.Uri;
                journalEntry.Parameters = navigationContext.Parameters;

                bool persistInHistory = PersistInHistory(view);

                Journal.RecordNavigation(journalEntry, persistInHistory);

                // The view can be informed of navigation
                MvvmHelpers.OnNavigatedTo(view, navigationContext);

                navigationCallback(new RegionNavigationResult(navigationContext, true));

                // Raise the navigated event when navigation is completed.
                RaiseNavigated(navigationContext);
            }
            catch (Exception e)
            {
                NotifyNavigationFailed(navigationContext, navigationCallback, e);
            }
        }
Пример #2
0
        private object InternalShowNotification(IRegion region, Uri viewUri)
        {
            var navigationContext = new NavigationContext(region.NavigationService, viewUri);
            var view = _regionNavigationContentLoader.LoadContent(region, navigationContext);

            if (view is FrameworkElement)
            {
                var navigatable = (view as FrameworkElement).DataContext as INavigationAware;
                if (navigatable != null)
                {
                    navigatable.OnNavigatedTo(navigationContext);
                }
            }
            return(view);
        }
        void ExecuteNavigation(NavigationContext navigationContext, object[] activeViews, Action <NavigationResult> navigationCallback)
        {
            try
            {
                NotifyActiveViewsNavigatingFrom(navigationContext, activeViews);

                object view = _regionNavigationContentLoader.LoadContent(Region, navigationContext);

                // Raise the navigating event just before activing the view.
                RaiseNavigating(navigationContext);

                Region.Activate(view);

                // Update the navigation journal before notifying others of navigaton
                IRegionNavigationJournalEntry journalEntry = _container.Resolve <IRegionNavigationJournalEntry>();
                journalEntry.Uri  = navigationContext.Uri;
                journalEntry.Args = navigationContext.Args;

                bool persistInHistory = PersistInHistory(view);

                Journal.RecordNavigation(journalEntry, persistInHistory);

                // The view can be informed of navigation
                void action(INavigationAware n) => n.OnNavigatedTo(navigationContext);

                MVVMHelper.ViewAndViewModelAction(view, (Action <INavigationAware>)action);

                navigationCallback(new NavigationResult(navigationContext, true));

                // Raise the navigated event when navigation is completed.
                RaiseNavigated(navigationContext);
            }
            catch (Exception e)
            {
                NotifyNavigationFailed(navigationContext, navigationCallback, e);
            }
        }
Пример #4
0
        private void ShowPopup(string viewName, Uri uri, string title, Action completedAction, bool maximize = false, bool isModal = false)
        {
            if (!_popupWindows.ContainsKey(viewName))
            {
                var    navigationContext = new NavigationContext(null, uri);
                object view;
                try
                {
                    view = _regionNavigationContentLoader.LoadContent(new Region(), navigationContext);
                }
                catch (Exception e)
                {
                    OnLoadContentException(e);
                    view = null;
                }
                if (view != null)
                {
                    if (view is FrameworkElement)
                    {
                        var navigatable = (view as FrameworkElement).DataContext as INavigationAware;
                        if (navigatable != null)
                        {
                            navigatable.OnNavigatedTo(navigationContext);
                        }
                    }

                    var configurationBehaviorService = new ConfigurationBehaviorService();
                    if (isModal)
                    {
                        var popupWindow = new PopupWindow();
                        popupWindow.IsMaximized = maximize;
                        if (title == null)
                        {
                            SetupPopupWindowTitle(popupWindow, view);
                        }
                        else
                        {
                            popupWindow.Title = title;
                        }

                        popupWindow.SubContent = view;
                        popupWindow.IsModal    = isModal;
                        _popupWindows.Add(viewName, popupWindow);

                        configurationBehaviorService.Watch(popupWindow);
                        EventHandler closedEventHandler = null;
                        closedEventHandler = (s, e) =>
                        {
                            popupWindow.Closed -= closedEventHandler;
                            configurationBehaviorService.Stop();
                            _popupWindows.Remove(viewName);
                            completedAction.Invoke();
                        };
                        popupWindow.Closed += closedEventHandler;
                        popupWindow.Show();
                    }
                    else
                    {
                        var floatableWindow = new FloatableWindow();

                        if (floatableWindow.Title == null)
                        {
                            SetupPopupWindowTitle(floatableWindow, view);
                        }
                        else
                        {
                            floatableWindow.Title = title;
                        }

                        floatableWindow.Content = view;
                        _popupWindows.Add(viewName, floatableWindow);
                        configurationBehaviorService.Watch(floatableWindow);

                        EventHandler closedEventHandler = null;
                        closedEventHandler = (s, e) =>
                        {
                            floatableWindow.Closed -= closedEventHandler;
                            configurationBehaviorService.Stop();
                            _popupWindows.Remove(viewName);
                            completedAction.Invoke();
                        };
                        floatableWindow.Closed += closedEventHandler;
                        floatableWindow.Show();
                    }
                }
            }
        }