示例#1
0
        public void EventFired_SourceObjectChangesToNull_ListensToSourceName()
        {
            EventTrigger eventTrigger = CreateEventTrigger();

            Grid      grid             = CreateGrid();
            Rectangle host             = CreateNamedElement <Rectangle>("rect");
            Button    sourceButton     = CreateNamedElement <Button>("sourcebutton");
            Button    sourceNameButton = CreateNamedElement <Button>("sourceNameButton");

            AddChildElement(grid, host);
            AddChildElement(grid, sourceButton);
            AddChildElement(grid, sourceNameButton);

            using (StubWindow window = new StubWindow(grid))
            {
                StubAction action = AttachTriggerToObject(eventTrigger, host);
                eventTrigger.SourceObject = sourceButton;
                eventTrigger.SourceName   = "sourceNameButton";
                eventTrigger.EventName    = "Click";
                eventTrigger.ClearValue(EventTriggerBase.SourceObjectProperty);
                System.Windows.RoutedEventArgs args = CreateClickEvent();

                sourceButton.RaiseEvent(args);
                Assert.AreEqual(action.InvokeCount, 0, "Click on source object button should not invoke the action, as the SourceObject has been cleared.");
                sourceNameButton.RaiseEvent(args);
                Assert.AreEqual(action.InvokeCount, 1, "Click on source name button when SourceObject has been cleared should invoke the action.");
            }
        }