public void EventArgsConverter_PassEventArgsToCommand() { var button = new Button(); int dataContextChangedCount = 0; int dataContextChangedCount2 = 0; button.DataContextChanged += (d, e) => dataContextChangedCount2++; var eventArgsConverter = new EventArgsConverterTestClass(); var eventToCommand = new EventToCommand() { EventName = "DataContextChanged", Command = new DelegateCommand(() => dataContextChangedCount++), EventArgsConverter = eventArgsConverter }; Interaction.GetBehaviors(button).Add(eventToCommand); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(0, eventArgsConverter.Count); button.DataContext = "1"; Assert.AreEqual(1, dataContextChangedCount); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(1, eventArgsConverter.Count); eventToCommand.PassEventArgsToCommand = false; button.DataContext = "2"; Assert.AreEqual(2, dataContextChangedCount); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(1, eventArgsConverter.Count); }
public void EventArgsConverter_PassEventArgsToCommand() { var button = new Button(); int dataContextChangedCount = 0; int dataContextChangedCount2 = 0; button.DataContextChanged += (d, e) => dataContextChangedCount2++; var eventArgsConverter = new EventArgsConverterTestClass(); var eventToCommand = new EventToCommand() { EventName = "DataContextChanged", Command = new DelegateCommand(() => dataContextChangedCount++), EventArgsConverter = eventArgsConverter }; Interaction.GetBehaviors(button).Add(eventToCommand); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(0, eventArgsConverter.Count); button.DataContext = "1"; Assert.AreEqual(1, dataContextChangedCount); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(1, eventArgsConverter.Count); eventToCommand.PassEventArgsToCommand = false; button.DataContext = "2"; Assert.AreEqual(2, dataContextChangedCount); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); #if !NETFX_CORE Assert.AreEqual(1, eventArgsConverter.Count); #else Assert.AreEqual(2, eventArgsConverter.Count); eventToCommand.EventArgsConverter = null; button.DataContext = "2"; Assert.AreEqual(3, dataContextChangedCount); Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount); Assert.AreEqual(2, eventArgsConverter.Count); #endif }