Пример #1
0
        private static void SetTargetCore(DependencyPropertyChangedEventArgs e, DependencyObject d, bool setContext)
        {
            if (_controller == null)
            {
                return;
            }

            if (e.NewValue != e.OldValue && e.NewValue != null)
            {
                var target = e.NewValue;

#if SILVERLIGHT
                var containerKey = e.NewValue as string;

                if (containerKey != null)
                {
                    target = _serviceLocator.GetInstance(null, containerKey);
                }
#endif

                var handler = new ActionMessageHandler(
                    new ActionHost(
                        target.GetType(),
                        _actionFactory,
                        _serviceLocator
                        ),
                    target
                    );

                _controller.AddHandler(d, handler, setContext);
            }
        }
Пример #2
0
        public void can_attach_a_message_handler_to_a_ui_element()
        {
            var dp      = new Button();
            var handler = Mock <IRoutedMessageHandler>();

            handler.Expect(x => x.Unwrap()).Return(handler);
            handler.Expect(x => x.Initialize(Arg <IInteractionNode> .Is.NotNull));

            controller.AddHandler(
                dp,
                handler,
                true
                );

            var node = dp.GetValue(DefaultRoutedMessageController.NodeProperty) as InteractionNode;

            node.ShouldNotBeNull();
            node.MessageHandler.ShouldBe(handler);
            dp.DataContext.ShouldBe(handler);
        }