예제 #1
0
        public void ParametersCanUseElementBindings()
        {
            Window.LoadContent(
                @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
	                xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                    xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity'
                    Name='MyButton'
                    Content='Bye!'
                    >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName='Click'>
                            <NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'>
                                <NavigateControllerAction.Parameters>
                                    <Parameter ParameterName='btn' Value='{Binding ElementName=MyButton}' />
                                    <Parameter ParameterName='btnContent' Value='{Binding ElementName=MyButton, Path=Content}' />
                                    <Parameter ParameterName='x' Value='Wazoo' />
                                </NavigateControllerAction.Parameters>
                            </NavigateControllerAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>");

            ExpectNavigationRequest("MyController", "MyAction", new { btn = Window.Find <Button>("MyButton"), btnContent = "Bye!", x = "Wazoo" });
            NavigationProperties.SetNavigator(Window, Navigator.Object);
            Window.Find <Button>("MyButton").ExecuteClick();
            Window.ProcessEvents();
        }
예제 #2
0
        public void ParametersCanUseDataContextBindings()
        {
            Window.LoadContent(
                @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
	                xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                    xmlns:magellan='http://xamlforge.com/magellan'
                    xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity'
                    Name='MyButton'
                    Content='Hello'
                    >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName='Click'>
                            <magellan:NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'>
                                <magellan:NavigateControllerAction.Parameters>
                                    <magellan:Parameter ParameterName='param' Value='{Binding}' />
                                    <magellan:Parameter ParameterName='paramA' Value='{Binding Path=A}' />
                                    <magellan:Parameter ParameterName='paramB' Value='{Binding Path=B}' />
                                </magellan:NavigateControllerAction.Parameters>
                            </magellan:NavigateControllerAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>");

            var dataContext = new { A = 3, B = 8 };

            ExpectNavigationRequest("MyController", "MyAction", new { param = dataContext, paramA = dataContext.A, paramB = dataContext.B });
            Window.DataContext = dataContext;
            NavigationProperties.SetNavigator(Window, Navigator.Object);
            Window.Find <Button>("MyButton").ExecuteClick();
            Window.ProcessEvents();
        }
예제 #3
0
        /// <summary>
        /// If the target implements <see cref="INavigationAware"/>, assigns the Navigator to it, and sets
        /// the NavigationProperties.Navigator attached property.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="request">The request.</param>
        protected virtual void AssignNavigator(object target, ResolvedNavigationRequest request)
        {
            if (target == null)
            {
                return;
            }

            var navigator = request.Navigator;

            if (navigator == null)
            {
                return;
            }

            var navigationAware  = target as INavigationAware;
            var dependencyObject = target as DependencyObject;

            if (navigationAware != null)
            {
                TraceSources.MagellanSource.TraceVerbose("The object '{0}' implements the INavigationAware interface, so it is being provided with a navigator.", navigationAware.GetType().Name);
                navigationAware.Navigator = navigator;
            }

            if (dependencyObject != null)
            {
                NavigationProperties.SetNavigator(dependencyObject, navigator);
                NavigationProperties.SetCurrentRequest(dependencyObject, request);
            }
        }
예제 #4
0
        public void ParametersCanUseRelativeSourceBindings()
        {
            Window.LoadContent(
                @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
	                xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                    xmlns:magellan='http://xamlforge.com/magellan'
                    xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity'
                    Name='MyButton'
                    Content='Hello'
                    >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName='Click'>
                            <magellan:NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'>
                                <magellan:NavigateControllerAction.Parameters>
                                    <magellan:Parameter ParameterName='win' Value='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}' />
                                    <magellan:Parameter ParameterName='winTitle' Value='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Title}' />
                                </magellan:NavigateControllerAction.Parameters>
                            </magellan:NavigateControllerAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>");

            ExpectNavigationRequest("MyController", "MyAction", new { win = Window, winTitle = "Hello" });
            Window.Title = "Hello";
            NavigationProperties.SetNavigator(Window, Navigator.Object);
            Window.Find <Button>("MyButton").ExecuteClick();
            Window.ProcessEvents();
        }
예제 #5
0
        public void CanCreateNavigatorForASourceElementWhenNavigatorAlreadySet()
        {
            var oldNavigator = new Mock <INavigator>();
            var button       = new Button();

            NavigationProperties.SetNavigator(button, oldNavigator.Object);

            var resolver  = new Mock <IRouteResolver>();
            var factory   = new NavigatorFactory(resolver.Object);
            var navigator = factory.GetOwningNavigator(button);

            Assert.AreEqual(navigator, oldNavigator.Object);
        }