Example #1
0
        public void T718930()
        {
            var bt = new Button();
            var cb = new System.Windows.Input.CommandBinding()
            {
                Command = System.Windows.Input.ApplicationCommands.Open
            };
            int exCount  = 0;
            int canCount = 0;

            cb.Executed   += (d, e) => { exCount++; };
            cb.CanExecute += (d, e) => { canCount++; e.CanExecute = true; };
            bt.CommandBindings.Add(cb);

            var bt1 = new Button();
            var etc = new EventToCommand()
            {
                EventName     = "Loaded",
                Command       = System.Windows.Input.ApplicationCommands.Open,
                CommandTarget = bt
            };

            Interaction.GetBehaviors(bt1).Add(etc);

            var root = new StackPanel();

            root.Children.Add(bt);
            root.Children.Add(bt1);
            Window.Content = root;
            Window.Show();
            DispatcherHelper.DoEvents();
            Assert.AreEqual(1, exCount);
            Assert.AreEqual(2, canCount);
        }
Example #2
0
        public void Q539009_2()
        {
            var control = new Grid()
            {
                Name = "control"
            };
            int counter2 = 0;
            int counter1 = 0;

            control.SizeChanged += (d, e) => counter2++;
            var eventToCommand = new EventToCommand()
            {
                SourceName = "control",
                EventName  = "SizeChanged",
                Command    = new DelegateCommand(() => counter1++),
            };

            Interaction.GetBehaviors(control).Add(eventToCommand);
            Window.Content = control;
            EnqueueShowWindow();
            EnqueueCallback(() => {
                Assert.AreEqual(counter2, counter1);
            });
            EnqueueTestComplete();
        }
Example #3
0
        public void TestInvokeWithBoundParameter()
        {
            var rectangle = new Rectangle();
            var trigger   = new EventToCommand();

            ((IAttachedObject)trigger).Attach(rectangle);

            const string parameterSent = "Hello world";

            var vm             = new TestViewModel();
            var bindingCommand = new Binding
            {
                Source = vm.ParameterCommand
            };

            var textBox = new TextBox
            {
                Text = parameterSent
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path   = new PropertyPath("Text")
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, bindingCommand);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);

            trigger.Invoke();

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(parameterSent, vm.ParameterReceived);
        }
Example #4
0
        public void B250383()
        {
            var control = new Button();

            control.IsEnabled = false;
            int loaded         = 0;
            var eventToCommand = new EventToCommand()
            {
                EventName = "Loaded", Command = new DelegateCommand(() => loaded++)
            };

            Interaction.GetBehaviors(control).Add(eventToCommand);
            Window.Content = control;
            EnqueueTestWindowMainCallback(() => {
                Assert.AreEqual(1, loaded);
                eventToCommand.SourceName = "button2";
            });

            EnqueueCallback(() => {
                control           = new Button();
                control.IsEnabled = false;
                eventToCommand    = new EventToCommand()
                {
                    EventName = "Loaded", ProcessEventsFromDisabledEventOwner = false, Command = new DelegateCommand(() => loaded++)
                };
                Interaction.GetBehaviors(control).Add(eventToCommand);
                loaded         = 0;
                Window.Content = control;
            });
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
                Assert.AreEqual(0, loaded);
            });
            EnqueueTestComplete();
        }
Example #5
0
        public void TestEnableAndDisableControlWithValueParameter()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button();

            ((IAttachedObject)trigger).Attach(button);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommandWithParameter
            };

            trigger.CommandParameterValue = "Hel";

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            Assert.IsFalse(button.IsEnabled);
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);

            trigger.CommandParameterValue = "Hello world";

            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
Example #6
0
        public void TestDisableCommandOnly()
        {
            var trigger   = new EventToCommand();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = true;

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);

            vm.CommandExecuted      = false;
            vm.EnableToggledCommand = false;

            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
Example #7
0
        public void TestDisableCommandAndRectangle()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = false;

            #if SILVERLIGHT3
            trigger.Command = binding;
            #else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            #endif

            #if !SILVERLIGHT
            Assert.IsFalse(rectangle.IsEnabled);
            #endif
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
Example #8
0
        void DispatcherTestCore(Action <EventToCommand> eventToCommandInitializer, bool checkImmediately)
        {
            var button = new Button();
            int dataContextChangedCount  = 0;
            int dataContextChangedCount2 = 0;

            button.DataContextChanged += (d, e) => dataContextChangedCount2++;
            var eventToCommand = new EventToCommand()
            {
                EventName          = "DataContextChanged",
                Command            = new DelegateCommand(() => dataContextChangedCount++),
                DispatcherPriority = DispatcherPriority.Render,
            };

            eventToCommandInitializer(eventToCommand);
            Interaction.GetBehaviors(button).Add(eventToCommand);
            Window.Content = button;
            Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount);
            button.DataContext = "1";
            if (!checkImmediately)
            {
                Assert.AreEqual(0, dataContextChangedCount);
            }
            else
            {
                Assert.AreEqual(1, dataContextChangedCount);
            }
            Assert.AreEqual(1, dataContextChangedCount2);
            EnqueueShowWindow();
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
                Assert.AreEqual(1, dataContextChangedCount);
            });
            EnqueueTestComplete();
        }
Example #9
0
        void Q554072_2Core(string eventName)
        {
            var control = new Grid();
            var bt      = new Button()
            {
                Name = "View"
            };

            control.Children.Add(bt);
            int counter1 = 0;
            int counter2 = 0;

            control.Loaded += (d, e) => counter1++;
            var eventToCommand1 = new EventToCommand()
            {
                PassEventArgsToCommand = true,
                EventName = eventName,
                Command   = new DelegateCommand(() => counter2++),
            };

            BindingOperations.SetBinding(eventToCommand1, EventToCommand.SourceObjectProperty, new Binding()
            {
                ElementName = "View"
            });
            Interaction.GetBehaviors(control).Add(eventToCommand1);
            Window.Content = control;
            EnqueueShowWindow();
            EnqueueCallback(() => {
                var evv = eventToCommand1.SourceObject;
                Assert.AreEqual(counter2, counter1);
            });
            EnqueueTestComplete();
        }
Example #10
0
        public void TestInvokeWithBoundParameter()
        {
            var rectangle = new Rectangle();
            var trigger = new EventToCommand();
            ((IAttachedObject)trigger).Attach(rectangle);

            const string ParameterSent = "Hello world";

            var vm = new TestViewModel();
            var bindingCommand = new Binding
            {
                Source = vm.ParameterCommand
            };

            var textBox = new TextBox
            {
                Text = ParameterSent
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path = new PropertyPath("Text")
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, bindingCommand);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);

            trigger.Invoke();

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(ParameterSent, vm.ParameterReceived);
        }
Example #11
0
        public void TestDisableCommandAndControl()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button();

            ((IAttachedObject)trigger).Attach(button);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = false;

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            Assert.IsFalse(button.IsEnabled);
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
Example #12
0
        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 async Task SourceChangedFireCount2()
        {
#endif
            var panel = new StackPanel();
            panel.Children.Add(new Button()
            {
                Name = "button2"
            });
            int gotFocusCount  = 0;
            var eventToCommand = new EventToCommand()
            {
                EventName = "GotFocus", Command = new DelegateCommand(() => gotFocusCount++)
            };
            Interaction.GetBehaviors(panel).Add(eventToCommand);
            Window.Content = panel;
#if NETFX_CORE
            await
#endif
            EnqueueTestWindowMainCallback(() => {
                Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount);
                eventToCommand.SourceName = "button2";
            });
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
                Assert.AreEqual(2, eventToCommand.RaiseSourceChangedCount);
            });
            EnqueueTestComplete();
        }
Example #14
0
        public void TestDisableCommandAndRectangle()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = false;

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

#if DOTNET
            Assert.IsFalse(rectangle.IsEnabled);
#endif

            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
Example #15
0
        public void TestInvokeWithValueParameter()
        {
            var rectangle = new Rectangle();
            var trigger   = new EventToCommand();

            ((IAttachedObject)trigger).Attach(rectangle);

            const string ParameterSent = "Hello world";

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

#if SILVERLIGHT
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            trigger.CommandParameterValue = ParameterSent;
            trigger.Invoke();

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(ParameterSent, vm.ParameterReceived);
        }
        public async Task Q539009_3()
        {
#endif
            var control = new Grid()
            {
                Name = "control"
            };
            int counter2 = 0;
            int counter1 = 0;
            control.SizeChanged += (d, e) => counter2++;
            var eventToCommand = new EventToCommand()
            {
                SourceObject = control,
                EventName    = "SizeChanged",
                Command      = new DelegateCommand(() => counter1++),
            };
            Interaction.GetBehaviors(control).Add(eventToCommand);
            Window.Content = control;
#if NETFX_CORE
            await
#endif
            EnqueueShowWindow();
            EnqueueCallback(() => {
                Assert.AreEqual(counter2, counter1);
            });
            EnqueueTestComplete();
        }
        public void EventArgsTwoWayConverter_PassEventArgsToCommand()
        {
            var button = new Button();
            var dataContextChangedCount = 0;
            var commandParameter        = 0;

            button.DataContext         = 0;
            button.DataContextChanged += (d, e) => dataContextChangedCount++;
            var eventArgsTwoWayConverter = new EventArgsTwoWayConverterTestClass();
            var eventToCommand           = new EventToCommand()
            {
                EventName          = "DataContextChanged",
                Command            = new DelegateCommand <int>((value) => commandParameter = value),
                EventArgsConverter = eventArgsTwoWayConverter
            };

            Interaction.GetBehaviors(button).Add(eventToCommand);
            Assert.AreEqual(0, dataContextChangedCount);
            Assert.AreEqual(0, commandParameter);
            button.DataContext = 1;
            Assert.AreEqual(1, dataContextChangedCount);
            Assert.AreEqual(1, commandParameter);
            Assert.AreEqual(1, eventArgsTwoWayConverter.CommandParameter);
            eventToCommand.PassEventArgsToCommand = false;
            button.DataContext = 2;
            Assert.AreEqual(2, dataContextChangedCount);
            Assert.AreEqual(0, commandParameter);
            Assert.AreEqual(1, eventArgsTwoWayConverter.CommandParameter);
        }
Example #18
0
        public void TestAlwaysInvoke()
        {
            var button = new Button
            {
                IsEnabled = false
            };

            var result = false;

            var command = new RelayCommand(
                () =>
            {
                result = true;
            });

            var trigger = new EventToCommand
            {
                Command = command
            };

            ((IAttachedObject)trigger).Attach(button);
            trigger.Invoke();
            Assert.IsFalse(result);

            trigger.AlwaysInvokeCommand = true;
            trigger.Invoke();
            Assert.IsTrue(result);
        }
Example #19
0
        public CalendarView()
        {
            InitializeComponent();

            //Name="ocv" CurrentViewMode="{Binding CurrentViewMode, Mode=TwoWay}" DateNavigator="{Binding DateNavigator}"
            //DataManager = "{Binding DataManager}" ActiveCalendar = "{Binding ActiveCalendar, Mode=OneWayToSource}"
            XamOutlookCalendarView view = new XamOutlookCalendarView();

            view.Name = "ocv";

            Binding commandBinding = new Binding();

            commandBinding.Source = DataContext;
            commandBinding.Path   = new PropertyPath("SelectedTimeRangeChangedCommand");

            EventToCommand eventToCommand = new EventToCommand();

            eventToCommand.EventArgsConverter = new XamOutlookCalendarViewSelectedTimeRangeChangedConverter();
            BindingOperations.SetBinding(eventToCommand, EventToCommand.CommandProperty, commandBinding);

            var triggers     = Interaction.GetTriggers(view);
            var eventTrigger = new System.Windows.Interactivity.EventTrigger()
            {
                EventName = "SelectedTimeRangeChanged"
            };

            eventTrigger.Actions.Add(eventToCommand);
            triggers.Add(eventTrigger);

            Binding currentViewModeBinding = new Binding();

            currentViewModeBinding.Source = DataContext;
            currentViewModeBinding.Path   = new System.Windows.PropertyPath("CurrentViewMode");
            currentViewModeBinding.Mode   = BindingMode.TwoWay;
            view.SetBinding(XamOutlookCalendarView.CurrentViewModeProperty, currentViewModeBinding);

            Binding dateNavigatorBinding = new Binding();

            dateNavigatorBinding.Source = DataContext;
            dateNavigatorBinding.Path   = new System.Windows.PropertyPath("DateNavigator");
            view.SetBinding(XamOutlookCalendarView.DateNavigatorProperty, dateNavigatorBinding);

            Binding dataManagerBinding = new Binding();

            dataManagerBinding.Source = DataContext;
            dataManagerBinding.Path   = new System.Windows.PropertyPath("DataManager");
            view.SetBinding(XamOutlookCalendarView.DataManagerProperty, dataManagerBinding);

            Binding activeCalendarBinding = new Binding();

            activeCalendarBinding.Source = DataContext;
            activeCalendarBinding.Path   = new System.Windows.PropertyPath("ActiveCalendar");
            activeCalendarBinding.Mode   = BindingMode.OneWayToSource;
            view.SetBinding(XamOutlookCalendarView.ActiveCalendarProperty, activeCalendarBinding);

            _placeHolder.Children.Add(view);
        }
        public void SetEvent_CheckEventNameIsReset_SetEventName_CheckEventIsReset()
        {
            EventToCommand eventToCommand = new EventToCommand();

            Assert.IsNotNull(eventToCommand.EventName);
            eventToCommand.Event = Validation.ErrorEvent;
            Assert.IsNull(eventToCommand.EventName);
            eventToCommand.EventName = "Unloaded";
            Assert.IsNull(eventToCommand.Event);
        }
Example #21
0
        public ButtonHome(string contendtext, string functionCode, string imagePath, int foreground = 0)
            : this()
        {
            this.imagePath   = imagePath;
            this.contendtext = contendtext;

            this.Padding = new Thickness(1, 0, 1, 1);
            this.Height  = 22;
            this.Width   = 120;

            sp.Orientation = Orientation.Horizontal;

            image.Source = new BitmapImage(new Uri("/ERP;component/Images/" + this.imagePath, UriKind.Relative));
            image.Height = 16;
            image.Width  = 16;
            image.Margin = new Thickness(0, 0, 2, 0);

            sp2.Width              = 92;
            sp2.Orientation        = Orientation.Horizontal;
            sp.HorizontalAlignment = HorizontalAlignment.Left;
            tb.Text   = this.contendtext; tb.FontSize = 13;
            tb.Margin = new Thickness(0, 4, 0, 0);
            //tb.FontFamily = new FontFamily("NSimSun");
            tb.Padding = new Thickness(0);
            //tb.FontWeight = FontWeights.Bold;
            if (foreground == 1)
            {
                tb.Foreground = new SolidColorBrush(ComColorConstants.DarkRed);
            }
            sp2.Children.Add(tb);

            sp.Children.Add(image);
            sp.Children.Add(sp2);

            this.Content = sp;

            var trigger = new System.Windows.Interactivity.EventTrigger {
                EventName = "Click"
            };
            var etc     = new EventToCommand();
            var binding =
                new Binding("CmdOpenWins")
            {
                Mode = BindingMode.OneWay
            };

            BindingOperations.SetBinding(etc, EventToCommand.CommandProperty, binding);
            etc.CommandParameter = functionCode;
            trigger.Actions.Add(etc);
            System.Windows.Interactivity.Interaction.GetTriggers(this).Add(trigger);
        }
Example #22
0
        public void TestEnableAndDisableControlWithBoundParameter()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button();

            ((IAttachedObject)trigger).Attach(button);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommandWithParameter
            };

            var textBox = new TextBox
            {
                Text = "Hel"
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path   = new PropertyPath("Text")
            };

#if SILVERLIGHT
            trigger.Command          = binding;
            trigger.CommandParameter = bindingParameter;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);
#endif

            Assert.IsFalse(button.IsEnabled);
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);

            textBox.Text = "Hello world";

#if SILVERLIGHT
            // Invoking CommandManager from unit tests fails in WPF
            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
#endif
        }
Example #23
0
        public void SetGotFocus(string bdCode)
        {
            var bd = new Binding("CmdGotFocus" + bdCode)
            {
                Mode = BindingMode.OneWay
            };
            var trigger = new System.Windows.Interactivity.EventTrigger {
                EventName = "GotFocus"
            };
            var etc = new EventToCommand();

            BindingOperations.SetBinding(etc, EventToCommand.CommandProperty, bd);
            trigger.Actions.Add(etc);
            System.Windows.Interactivity.Interaction.GetTriggers(this).Add(trigger);
        }
Example #24
0
        public void TestAssociatedObjectImplementsINotifyPropertyChanged2()
        {
            Grid element      = new Grid();
            var  testBehavior = new EventToCommand();

            BindingOperations.SetBinding(testBehavior, EventToCommand.CommandParameterProperty, new Binding()
            {
                Path           = new PropertyPath("AssociatedObject"),
                RelativeSource = RelativeSource.Self
            });
            Interaction.GetBehaviors(element).Add(testBehavior);
            Assert.AreSame(element, testBehavior.CommandParameter);
            Interaction.GetBehaviors(element).Remove(testBehavior);
            Assert.IsNull(testBehavior.CommandParameter);
        }
Example #25
0
        public Tuple <string, ICommand> Get(FlowContext flowEvent, EventToCommand eventToCommand)
        {
            if (!commandCreationDictionary.ContainsKey(eventToCommand.Command))
            {
                throw new ArgumentException("Command:{0} not registered", eventToCommand.Command.FullName);
            }

            var commandsOfType = commandCreationDictionary[eventToCommand.Command];

            if (!commandsOfType.ContainsKey(eventToCommand.CommandName))
            {
                throw new ArgumentException("Command:{0} not registered with the expected name", eventToCommand.CommandName);
            }

            return(new Tuple <string, ICommand>(eventToCommand.CommandName, commandsOfType[eventToCommand.CommandName].Invoke(flowEvent)));
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     var ctx = value as CommandContext;
     if (ctx == null) return null;
     var result = new Collection<EventToCommand>();
     foreach (var cmd in ctx.Commands.OfType<EventCommandModel>()
         .Where(p => p.EventName.IsNotEmpty() && p.Target.CIEquals(Target)))
     {
         EventToCommand e = new EventToCommand();
         e.Command = (System.Windows.Input.ICommand)cmd;
         e.EventName = cmd.EventName;
         e.PassEventArgsToCommand = true;
         result.Add(e);
     }
     return result;
 }
        public void NameScopeAccessProviderSourceTest()
        {
            var window         = new ContentControl();
            var eventToCommand = new EventToCommand();
            var testViewModel  = new TestViewModel();

            window.Content = testViewModel;
            int execCount = 0;

            eventToCommand.Command      = new DelegateCommand(() => execCount++);
            eventToCommand.SourceObject = testViewModel;
            eventToCommand.EventName    = "TestEvent";
            Interaction.GetBehaviors(window).Add(eventToCommand);
            testViewModel.RaiseTestEvent();
            Assert.AreEqual(1, execCount);
        }
Example #28
0
        protected void SetDropDownClosed(string bindFunctionName)
        {
            var trigger = new System.Windows.Interactivity.EventTrigger {
                EventName = "DropDownClosed"
            };
            var etc     = new EventToCommand();
            var binding =
                new Binding("CmdDropDownClosed" + bindFunctionName)
            {
                Mode = BindingMode.OneWay
            };

            BindingOperations.SetBinding(etc, EventToCommand.CommandProperty, binding);
            trigger.Actions.Add(etc);
            System.Windows.Interactivity.Interaction.GetTriggers(this).Add(trigger);
        }
Example #29
0
        public void TestInvokeWithoutParameter()
        {
            var trigger = new EventToCommand();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.SimpleCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
Example #30
0
        public void TestAssociatedObjectImplementsINotifyPropertyChanged2()
        {
            Grid element      = new Grid();
            var  testBehavior = new EventToCommand();

            BindingOperations.SetBinding(testBehavior, EventToCommand.CommandParameterProperty, new Binding()
            {
                Path = new PropertyPath("AssociatedObject"),
#if !NETFX_CORE && !SILVERLIGHT
                RelativeSource = RelativeSource.Self
#else
                RelativeSource = new RelativeSource()
                {
                    Mode = RelativeSourceMode.Self
                }
#endif
            });
        public void SetEvent_RaiseEvent_CheckCommandExecuted()
        {
            bool           commandExecuted = false;
            EventToCommand eventToCommand  = new EventToCommand()
            {
                Command = new DelegateCommand(() => {
                    commandExecuted = true;
                })
            };
            Button button = new Button();

            eventToCommand.Event = Button.ClickEvent;
            eventToCommand.Attach(button);
            button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, button));
            EnqueueWindowUpdateLayout();
            Assert.IsTrue(commandExecuted);
        }
Example #32
0
        public ButtonHelp(string commandname)
            : this()
        {
            var trigger = new System.Windows.Interactivity.EventTrigger {
                EventName = "Click"
            };
            var etc     = new EventToCommand();
            var binding =
                new Binding(commandname)
            {
                Mode = BindingMode.OneWay
            };

            BindingOperations.SetBinding(etc, EventToCommand.CommandProperty, binding);
            trigger.Actions.Add(etc);
            System.Windows.Interactivity.Interaction.GetTriggers(this).Add(trigger);
        }
Example #33
0
        public void TestInvokeWithoutParameter()
        {
            var trigger   = new EventToCommand();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.SimpleCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
Example #34
0
        public CalendarGroup()
        {
            InitializeComponent();

            //workaround for XAML build error in Core 3
            XamDateNavigator dateNav = new XamDateNavigator();

            dateNav.Margin = new Thickness(5);
            dateNav.HighlightDayCriteria = HighlightDayCriteria.DaysWithActivity;
            dateNav.Background           = new SolidColorBrush(Colors.Transparent);

            Binding dataManagerBinding = new Binding();

            dataManagerBinding.Source = DataContext;
            dataManagerBinding.Path   = new PropertyPath("DataManager");
            dateNav.SetBinding(XamDateNavigator.DataManagerProperty, dataManagerBinding);

            Binding selectedDatesBinding = new Binding();

            selectedDatesBinding.Source = DataContext;
            selectedDatesBinding.Path   = new PropertyPath("SelectedDates");
            dateNav.SetBinding(XamDateNavigatorProperties.SelectedDatesProperty, selectedDatesBinding);

            Binding commandBinding = new Binding();

            commandBinding.Source = DataContext;
            commandBinding.Path   = new PropertyPath("DateNavigatorSelectedDatesCommand");

            EventToCommand eventToCommand = new EventToCommand();

            eventToCommand.EventArgsConverter = new DateNavigatorSelectedDatesConverter();
            BindingOperations.SetBinding(eventToCommand, EventToCommand.CommandProperty, commandBinding);

            var triggers     = Interaction.GetTriggers(dateNav);
            var eventTrigger = new System.Windows.Interactivity.EventTrigger()
            {
                EventName = "SelectedDatesChanged"
            };

            eventTrigger.Actions.Add(eventToCommand);
            triggers.Add(eventTrigger);

            _dateNavigatorPlaceholder.Children.Add(dateNav);
        }
Example #35
0
        public void TestInvokeWithValueParameter()
        {
            var rectangle = new Rectangle();
            var trigger = new EventToCommand();
            ((IAttachedObject)trigger).Attach(rectangle);

            const string ParameterSent = "Hello world";

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.CommandParameterValue = ParameterSent;
            trigger.Invoke();

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(ParameterSent, vm.ParameterReceived);
        }
Example #36
0
        public void TestEnableAndDisableControlWithValueParameter()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button();
            ((IAttachedObject)trigger).Attach(button);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommandWithParameter
            };

            trigger.CommandParameterValue = "Hel";

            #if SILVERLIGHT3
            trigger.Command = binding;
            #else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            #endif

            Assert.IsFalse(button.IsEnabled);
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);

            trigger.CommandParameterValue = "Hello world";

            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
 public void MarkRoutedEventsAsHandled() {
     var button = new Button() { Name = "View" };
     int counter1 = 0;
     int counter2 = 0;
     int counter3 = 0;
     button.Loaded += (d, e) => counter1++;
     var eventToCommand1 = new EventToCommand() {
         PassEventArgsToCommand = true,
         EventName = "Loaded",
         Command = new DelegateCommand(() => counter2++),
         SourceName = "View",
         MarkRoutedEventsAsHandled = true,
     };
     var eventToCommand2 = new EventToCommand() {
         PassEventArgsToCommand = true,
         EventName = "Loaded",
         Command = new DelegateCommand(() => counter3++),
         SourceName = "View",
         MarkRoutedEventsAsHandled = true,
     };
     Interaction.GetBehaviors(button).Add(eventToCommand1);
     Interaction.GetBehaviors(button).Add(eventToCommand2);
     Window.Content = button;
     EnqueueShowWindow();
     EnqueueCallback(() => {
         Assert.AreEqual(1, counter1);
         Assert.AreEqual(1, counter2);
         Assert.AreEqual(0, counter3);
     });
     EnqueueTestComplete();
 }
        public void DispatcherDefaultValues() {
            EventToCommand eventToCommand = new EventToCommand();
            Assert.AreEqual(null, eventToCommand.UseDispatcher);
            Assert.AreEqual(null, eventToCommand.DispatcherPriority);
            Assert.AreEqual(false, eventToCommand.ActualUseDispatcher);
            Assert.AreEqual(DispatcherPriority.Normal, eventToCommand.ActualDispatcherPriority);

            eventToCommand.DispatcherPriority = DispatcherPriority.Normal;
            Assert.AreEqual(true, eventToCommand.ActualUseDispatcher);
            Assert.AreEqual(DispatcherPriority.Normal, eventToCommand.ActualDispatcherPriority);
            eventToCommand.DispatcherPriority = DispatcherPriority.Render;
            Assert.AreEqual(DispatcherPriority.Render, eventToCommand.ActualDispatcherPriority);

            eventToCommand.UseDispatcher = false;
            Assert.AreEqual(false, eventToCommand.ActualUseDispatcher);

            eventToCommand.DispatcherPriority = null;
            eventToCommand.UseDispatcher = true;
            Assert.AreEqual(true, eventToCommand.ActualUseDispatcher);
            Assert.AreEqual(DispatcherPriority.Normal, eventToCommand.ActualDispatcherPriority);
        }
        void DispatcherTestCore(Action<EventToCommand> eventToCommandInitializer, bool checkImmediately) {
#else
        async Task DispatcherTestCore(Action<EventToCommand> eventToCommandInitializer, bool checkImmediately) {
#endif
            var button = new Button();
            int dataContextChangedCount = 0;
            int dataContextChangedCount2 = 0;
            button.DataContextChanged += (d, e) => dataContextChangedCount2++;
            var eventToCommand = new EventToCommand() {
                EventName = "DataContextChanged",
                Command = new DelegateCommand(() => dataContextChangedCount++),
#if !SILVERLIGHT && !NETFX_CORE
                DispatcherPriority = DispatcherPriority.Render,
#endif
            };
            eventToCommandInitializer(eventToCommand);
            Interaction.GetBehaviors(button).Add(eventToCommand);
            Window.Content = button;
            Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount);
            button.DataContext = "1";
            if(!checkImmediately)
                Assert.AreEqual(0, dataContextChangedCount);
            else Assert.AreEqual(1, dataContextChangedCount);
            Assert.AreEqual(1, dataContextChangedCount2);
#if NETFX_CORE
            await
#endif
            EnqueueShowWindow();
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
#if !NETFX_CORE
                Assert.AreEqual(1, dataContextChangedCount);
#else
                Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount);
#endif
            });
            EnqueueTestComplete();
        }
        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
        }
        public void SourceChangedFireCount1() {
            var panel = new StackPanel();
            panel.Children.Add(new Button() { Name = "button1" });
            panel.Children.Add(new Button() { Name = "button2" });
            int gotFocusCount = 0;
            var eventToCommand = new EventToCommand() { SourceObject = panel.Children[0], EventName = "GotFocus", Command = DelegateCommandFactory.Create(() => gotFocusCount++, false) };
            Interaction.GetBehaviors(panel).Add(eventToCommand);
            Window.Content = panel;
            EnqueueShowWindow();
            EnqueueCallback(() => {
                Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount);
                eventToCommand.SourceName = "button2";
                Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount);

                Assert.AreEqual(0, gotFocusCount);
                ((Button)panel.Children[1]).Focus();
            });
            EnqueueConditional(() => gotFocusCount == 0);
            EnqueueCallback(() => {
                ((Button)panel.Children[0]).Focus();
            });
            EnqueueConditional(() => gotFocusCount == 1);
            EnqueueTestComplete();
        }
 public void Q539009_2() {
     var control = new Grid() { Name = "control" };
     int counter2 = 0;
     int counter1 = 0;
     control.SizeChanged += (d, e) => counter2++;
     var eventToCommand = new EventToCommand() {
         SourceName = "control",
         EventName = "SizeChanged",
         Command = new DelegateCommand(() => counter1++),
     };
     Interaction.GetBehaviors(control).Add(eventToCommand);
     Window.Content = control;
     EnqueueShowWindow();
     EnqueueCallback(() => {
         Assert.AreEqual(counter2, counter1);
     });
     EnqueueTestComplete();
 }
        void Q554072_1Core(string eventName) {
#else
        async Task Q554072_1Core(string eventName) {
#endif
            var control = new Grid();
            var bt = new Button() { Name = "View" };
            control.Children.Add(bt);
            int counter1 = 0;
            int counter2 = 0;
            int counter3 = 0;
            control.Loaded += (d, e) => counter1++;
            var eventToCommand1 = new EventToCommand() {
                PassEventArgsToCommand = true,
                EventName = eventName,
                Command = new DelegateCommand(() => counter2++),
                SourceName = "View",
            };
            var eventToCommand2 = new EventToCommand() {
                PassEventArgsToCommand = true,
                EventName = eventName,
                Command = new DelegateCommand(() => counter3++),
                SourceName = "View",
            };
            Interaction.GetBehaviors(control).Add(eventToCommand1);
            Interaction.GetBehaviors(bt).Add(eventToCommand2);
            Window.Content = control;
#if NETFX_CORE
            await
#endif
            EnqueueShowWindow();
            EnqueueCallback(() => {
                Assert.AreEqual(counter2, counter1);
                Assert.AreEqual(counter3, counter1);
            });
            EnqueueTestComplete();
        }
#if !NETFX_CORE
        void Q554072_2Core(string eventName) {
#else
        async Task Q554072_2Core(string eventName) {
#endif
            var control = new Grid();
            var bt = new Button() { Name = "View" };
            control.Children.Add(bt);
            int counter1 = 0;
            int counter2 = 0;
            control.Loaded += (d, e) => counter1++;
            var eventToCommand1 = new EventToCommand() {
                PassEventArgsToCommand = true,
                EventName = eventName,
                Command = new DelegateCommand(() => counter2++),
            };
            BindingOperations.SetBinding(eventToCommand1, EventToCommand.SourceObjectProperty, new Binding() { ElementName = "View" });
            Interaction.GetBehaviors(control).Add(eventToCommand1);
            Window.Content = control;
#if NETFX_CORE
            await
#endif
            EnqueueShowWindow();
            EnqueueCallback(() => {
                var evv = eventToCommand1.SourceObject;
                Assert.AreEqual(counter2, counter1);
            });
            EnqueueTestComplete();
        }

        [Test, Asynchronous]
        public async Task Q539009_3() {
#endif
            var control = new Grid() { Name = "control" };
            int counter2 = 0;
            int counter1 = 0;
            control.SizeChanged += (d, e) => counter2++;
            var eventToCommand = new EventToCommand() {
                SourceObject = control,
                EventName = "SizeChanged",
                Command = new DelegateCommand(() => counter1++),
            };
            Interaction.GetBehaviors(control).Add(eventToCommand);
            Window.Content = control;
#if NETFX_CORE
            await
#endif
            EnqueueShowWindow();
            EnqueueCallback(() => {
                Assert.AreEqual(counter2, counter1);
            });
            EnqueueTestComplete();
        }
        public async Task B250383() {
#endif
            var control = new Button();
            control.IsEnabled = false;
            int loaded = 0;
            var eventToCommand = new EventToCommand() { EventName = "Loaded", Command = new DelegateCommand(() => loaded++) };
            Interaction.GetBehaviors(control).Add(eventToCommand);
            Window.Content = control;
#if NETFX_CORE
            await
#endif
            EnqueueTestWindowMainCallback(() => {
                Assert.AreEqual(1, loaded);
                eventToCommand.SourceName = "button2";
            });

            EnqueueCallback(() => {
                control = new Button();
                control.IsEnabled = false;
                eventToCommand = new EventToCommand() { EventName = "Loaded", ProcessEventsFromDisabledEventOwner = false, Command = new DelegateCommand(() => loaded++) };
                Interaction.GetBehaviors(control).Add(eventToCommand);
                loaded = 0;
                Window.Content = control;
            });
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
                Assert.AreEqual(0, loaded);
            });
            EnqueueTestComplete();
        }
 public void NameScopeAccessProviderSourceTest() {
     var window = new ContentControl();
     var eventToCommand = new EventToCommand();
     var testViewModel = new TestViewModel();
     window.Content = testViewModel;
     int execCount = 0;
     eventToCommand.Command = new DelegateCommand(() => execCount++);
     eventToCommand.SourceObject = testViewModel;
     eventToCommand.EventName = "TestEvent";
     Interaction.GetBehaviors(window).Add(eventToCommand);
     testViewModel.RaiseTestEvent();
     Assert.AreEqual(1, execCount);
 }
        public async Task B236199_DataContextChangedSubscription() {
#endif
            var button = new Button();
            int dataContextChangedCount = 0;
            int dataContextChangedCount2 = 0;
            button.DataContextChanged += (d, e) => dataContextChangedCount2++;
            var eventToCommand = new EventToCommand() { EventName = "DataContextChanged", Command = new DelegateCommand(() => dataContextChangedCount++) };
            Interaction.GetBehaviors(button).Add(eventToCommand);
            Window.Content = button;
#if NETFX_CORE
            await
#endif
            EnqueueTestWindowMainCallback(() => {
                Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount);
                button.DataContext = "1";
                Assert.AreEqual(dataContextChangedCount2, dataContextChangedCount);
            });
            EnqueueTestComplete();
        }
        public async Task SourceChangedFireCount2() {
#endif
            var panel = new StackPanel();
            panel.Children.Add(new Button() { Name = "button2" });
            int gotFocusCount = 0;
            var eventToCommand = new EventToCommand() { EventName = "GotFocus", Command = new DelegateCommand(() => gotFocusCount++) };
            Interaction.GetBehaviors(panel).Add(eventToCommand);
            Window.Content = panel;
#if NETFX_CORE
            await
#endif
            EnqueueTestWindowMainCallback(() => {
                Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount);
                eventToCommand.SourceName = "button2";

            });
            EnqueueWindowUpdateLayout();
            EnqueueCallback(() => {
                Assert.AreEqual(2, eventToCommand.RaiseSourceChangedCount);
            });
            EnqueueTestComplete();
        }
 void Q554072_2Core(string eventName) {
     var control = new Grid();
     var bt = new Button() { Name = "View" };
     control.Children.Add(bt);
     int counter1 = 0;
     int counter2 = 0;
     control.Loaded += (d, e) => counter1++;
     var eventToCommand1 = new EventToCommand() {
         PassEventArgsToCommand = true,
         EventName = eventName,
         Command = new DelegateCommand(() => counter2++),
     };
     BindingOperations.SetBinding(eventToCommand1, EventToCommand.SourceObjectProperty, new Binding() { ElementName = "View" });
     Interaction.GetBehaviors(control).Add(eventToCommand1);
     Window.Content = control;
     EnqueueShowWindow();
     EnqueueCallback(() => {
         var evv = eventToCommand1.SourceObject;
         Assert.AreEqual(counter2, counter1);
     });
     EnqueueTestComplete();
 }
 void Q554072_1Core(string eventName) {
     var control = new Grid();
     var bt = new Button() { Name = "View" };
     control.Children.Add(bt);
     int counter1 = 0;
     int counter2 = 0;
     int counter3 = 0;
     control.Loaded += (d, e) => counter1++;
     var eventToCommand1 = new EventToCommand() {
         PassEventArgsToCommand = true,
         EventName = eventName,
         Command = new DelegateCommand(() => counter2++),
         SourceName = "View",
     };
     var eventToCommand2 = new EventToCommand() {
         PassEventArgsToCommand = true,
         EventName = eventName,
         Command = new DelegateCommand(() => counter3++),
         SourceName = "View",
     };
     Interaction.GetBehaviors(control).Add(eventToCommand1);
     Interaction.GetBehaviors(bt).Add(eventToCommand2);
     Window.Content = control;
     EnqueueShowWindow();
     EnqueueCallback(() => {
         Assert.AreEqual(counter2, counter1);
         Assert.AreEqual(counter3, counter1);
     });
     EnqueueTestComplete();
 }
Example #51
0
        public void TestEnableCommandAndControl()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button
            {
                IsEnabled = false
            };

            ((IAttachedObject)trigger).Attach(button);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = true;

            #if SILVERLIGHT3
            trigger.Command = binding;
            #else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            #endif

            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
 public void SetEvent_CheckEventNameIsReset_SetEventName_CheckEventIsReset() {
     EventToCommand eventToCommand = new EventToCommand();
     Assert.IsNotNull(eventToCommand.EventName);
     eventToCommand.Event = Validation.ErrorEvent;
     Assert.IsNull(eventToCommand.EventName);
     eventToCommand.EventName = "Unloaded";
     Assert.IsNull(eventToCommand.Event);
 }
Example #53
0
        public void TestEnableAndDisableControlWithBoundParameter()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

            var button = new Button();
            ((IAttachedObject)trigger).Attach(button);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommandWithParameter
            };

            var textBox = new TextBox
            {
                Text = "Hel"
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path = new PropertyPath("Text")
            };

            #if SILVERLIGHT3
            trigger.Command = binding;
            trigger.CommandParameter = bindingParameter;
            #else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);
            #endif

            Assert.IsFalse(button.IsEnabled);
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);

            textBox.Text = "Hello world";

            #if SILVERLIGHT
            // Invoking CommandManager from unit tests fails in WPF
            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
            #endif
        }
Example #54
0
        public void TestDisableCommandOnly()
        {
            var trigger = new EventToCommand();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ToggledCommand
            };

            vm.EnableToggledCommand = true;

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);

            vm.CommandExecuted = false;
            vm.EnableToggledCommand = false;

            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
 public void SetEvent_RaiseEvent_CheckCommandExecuted() {
     bool commandExecuted = false;
     EventToCommand eventToCommand = new EventToCommand() {
         Command = new DelegateCommand(() => {
             commandExecuted = true;
         })
     };
     Button button = new Button();
     eventToCommand.Event = Button.ClickEvent;
     eventToCommand.Attach(button);
     button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, button));
     EnqueueWindowUpdateLayout();
     Assert.IsTrue(commandExecuted);
 }