public void NavigateWithTransitions()
        {
            var navigator = new FrameNavigationServiceWrapper(Frame.Dispatcher, Frame);

            navigator.NavigateDirectToContent(new Button());
            Assert.IsNull(TransitionSelector.CurrentTransition);
            ProcessEventsSlow();

            navigator.NavigateDirectToContent(new Button(), "ZoomIn");
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "ZoomIn");
            ProcessEventsSlow();

            navigator.NavigateDirectToContent(new Button(), "Forward");
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "Forward");
            ProcessEventsSlow();

            navigator.GoBack();
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "Back");
            ProcessEventsSlow();

            navigator.GoForward();
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "Forward");
            ProcessEventsSlow();

            navigator.GoBack();
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "Back");
            ProcessEventsSlow();

            navigator.GoBack();
            Assert.AreEqual(TransitionSelector.CurrentTransition.Name, "ZoomOut");
            ProcessEventsSlow();
        }
Пример #2
0
    	/// <summary>
        /// Creates an <see cref="INavigator"/> bound to the navigation service that owns a given source
        /// element. This method can  be called multiple times for the same <paramref name="sourceElement"/>.
        /// </summary>
        /// <param name="sourceElement">A UI element that lives inside the frame that you want a navigator
        /// for.</param>
        /// <returns>
        /// An instance of the <see cref="INavigator"/> interface which can be used for navigation.
        /// </returns>
        public INavigator GetOwningNavigator(UIElement sourceElement)
        {
            Guard.ArgumentNotNull(sourceElement, "sourceElement");

            var existingNavigator = NavigationProperties.GetNavigator(sourceElement);
            if (existingNavigator != null)
            {
                return existingNavigator;
            }

            Func<INavigationService> lazyFrameGetter = () =>
            {
                var frame = null as Frame;
                DependencyObject parent = sourceElement;
                while (parent != null)
                {
                    frame = parent as Frame;
                    if (frame != null)
                        break;
                    parent = VisualTreeHelper.GetParent(parent);
                }

                if (frame == null)
                {
                    throw new ImpossibleNavigationRequestException("The Navigator for this UI element is not avaialable. Please ensure the current view has been loaded into a frame, or that the NavigationProperties.Navigator attached property has been set.");
                }

                var wrapper = new FrameNavigationServiceWrapper(sourceElement.Dispatcher, frame);
                return wrapper;
            };

            return NewNavigator(lazyFrameGetter, null);
        }