This System.Windows.Interactivity.TriggerAction can be used to bind any event on any FrameworkElement to an ICommand. Typically, this element is used in XAML to connect the attached element to a command located in a ViewModel. This trigger can only be attached to a FrameworkElement or a class deriving from FrameworkElement.
        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);
        }
예제 #2
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);
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Window = ((Inter_face.ModifyFilenamesWindow)(target));
                return;

            case 2:
                this.ClosedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.filenamesListBox = ((System.Windows.Controls.ListBox)(target));
                return;

            case 5:
                this.DragEnterEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 6:
                this.DropEventToComand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 7:
                this.UpButton = ((System.Windows.Controls.Button)(target));
                return;

            case 8:
                this.DownButton = ((System.Windows.Controls.Button)(target));
                return;

            case 9:
                this.AddButton = ((System.Windows.Controls.Button)(target));
                return;

            case 10:
                this.DeleteButton = ((System.Windows.Controls.Button)(target));
                return;

            case 11:
                this.RemoveallButton = ((System.Windows.Controls.Button)(target));
                return;

            case 12:
                this.OkButton = ((System.Windows.Controls.Button)(target));
                return;

            case 13:
                this.CancelButton = ((System.Windows.Controls.Button)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #4
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Window = ((Inter_face.ModifyCdldataWindow)(target));
                return;

            case 2:
                this.LoadToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.cdllistbox = ((System.Windows.Controls.ListBox)(target));
                return;

            case 5:
                this.UpButton = ((System.Windows.Controls.Button)(target));
                return;

            case 6:
                this.DownButton = ((System.Windows.Controls.Button)(target));
                return;

            case 7:
                this.DeleteButton = ((System.Windows.Controls.Button)(target));
                return;

            case 8:
                this.ModifyButton = ((System.Windows.Controls.Button)(target));
                return;

            case 9:
                this.AddButton = ((System.Windows.Controls.Button)(target));
                return;

            case 10:
                this.SaveButton = ((System.Windows.Controls.Button)(target));
                return;

            case 11:
                this.CancelButton = ((System.Windows.Controls.Button)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #5
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);
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ContentGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 2:
                this.Page2Button = ((System.Windows.Controls.Button)(target));
                return;

            case 3:
                this.Page2ButtonClicked = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #7
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ldhinfoWindow = ((Inter_face.LdhInfoWindow)(target));
                return;

            case 2:
                this.ClosedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.ldhinfoListView = ((System.Windows.Controls.ListView)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #8
0
        private static void OnCommandChanged(
            EventToCommand element,
            DependencyPropertyChangedEventArgs e)
        {
            if (element == null)
            {
                return;
            }

            if (e.OldValue != null)
            {
                ((ICommand)e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
            }

            var command = (ICommand)e.NewValue;

            if (command != null)
            {
                command.CanExecuteChanged += element.OnCommandCanExecuteChanged;
            }

            element.EnableDisableElement();
        }
        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 SILVERLIGHT
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            Assert.IsTrue(button.IsEnabled);
            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
예제 #10
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.cmbFilterStates = ((System.Windows.Controls.ComboBox)(target));
     return;
     case 2:
     this.filterByRangeDate = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 3:
     this.lblFrom = ((System.Windows.Controls.Label)(target));
     return;
     case 4:
     this.dateFrom = ((System.Windows.Controls.DatePicker)(target));
     return;
     case 5:
     this.lblTo = ((System.Windows.Controls.Label)(target));
     return;
     case 6:
     this.dateTo = ((System.Windows.Controls.DatePicker)(target));
     return;
     case 7:
     this.filterByUser = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 8:
     this.cmbUsers = ((System.Windows.Controls.ComboBox)(target));
     return;
     case 9:
     this.btnGetLog = ((System.Windows.Controls.Button)(target));
     return;
     case 10:
     this.LoadedWin = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
     return;
     }
     this._contentLoaded = true;
 }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ModifyQujianWindow1 = ((Inter_face.ModifyQujianWindow)(target));
                return;

            case 2:
                this.ClosedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.DivSlider = ((System.Windows.Controls.Slider)(target));
                return;

            case 5:
                this.ValueChangedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 6:
                this.StartLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.EndLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.DivGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 9:
                this.ParttwoLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 10:
                this.Hlabel = ((System.Windows.Controls.Label)(target));
                return;

            case 11:
                this.SLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 12:
                this.LenTextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.LcLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 14:
                this.OkButton = ((System.Windows.Controls.Button)(target));
                return;

            case 15:
                this.CancelButton = ((System.Windows.Controls.Button)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #12
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);
        }
예제 #13
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 13 "..\..\..\MainWindow.xaml"
                ((Inter_face.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.RibbonWindow_Loaded);

            #line default
            #line hidden
                return;

            case 2:

            #line 53 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.Image)(target)).ImageFailed += new System.EventHandler <System.Windows.ExceptionRoutedEventArgs>(this.Image_ImageFailed);

            #line default
            #line hidden
                return;

            case 3:
                this.ClosedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 4:
                this.CreatNewWork = ((Fluent.Button)(target));

            #line 315 "..\..\..\MainWindow.xaml"
                this.CreatNewWork.Click += new System.Windows.RoutedEventHandler(this.CreatNewWork_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.loadformdatabase = ((Fluent.Button)(target));

            #line 316 "..\..\..\MainWindow.xaml"
                this.loadformdatabase.Click += new System.Windows.RoutedEventHandler(this.loadformdatabase_Click);

            #line default
            #line hidden
                return;

            case 6:
                this.loadformSourceZip = ((Fluent.Button)(target));

            #line 317 "..\..\..\MainWindow.xaml"
                this.loadformSourceZip.Click += new System.Windows.RoutedEventHandler(this.loadformSourceZip_Click);

            #line default
            #line hidden

            #line 317 "..\..\..\MainWindow.xaml"
                this.loadformSourceZip.DragEnter += new System.Windows.DragEventHandler(this.loadformSourceZip_DragEnter);

            #line default
            #line hidden

            #line 317 "..\..\..\MainWindow.xaml"
                this.loadformSourceZip.Drop += new System.Windows.DragEventHandler(this.loadformSourceZip_Drop);

            #line default
            #line hidden
                return;

            case 7:
                this.loadformOpZip = ((Fluent.Button)(target));

            #line 318 "..\..\..\MainWindow.xaml"
                this.loadformOpZip.Click += new System.Windows.RoutedEventHandler(this.loadformOpZip_Click);

            #line default
            #line hidden

            #line 318 "..\..\..\MainWindow.xaml"
                this.loadformOpZip.DragEnter += new System.Windows.DragEventHandler(this.loadformOpZip_DragEnter);

            #line default
            #line hidden

            #line 318 "..\..\..\MainWindow.xaml"
                this.loadformOpZip.Drop += new System.Windows.DragEventHandler(this.loadformOpZip_Drop);

            #line default
            #line hidden
                return;

            case 8:
                this.SaveSourcedata = ((Fluent.Button)(target));

            #line 321 "..\..\..\MainWindow.xaml"
                this.SaveSourcedata.Click += new System.Windows.RoutedEventHandler(this.SaveSourcedata_Click);

            #line default
            #line hidden
                return;

            case 9:
                this.SaveOpdata = ((Fluent.Button)(target));

            #line 322 "..\..\..\MainWindow.xaml"
                this.SaveOpdata.Click += new System.Windows.RoutedEventHandler(this.SaveOpdata_Click);

            #line default
            #line hidden
                return;

            case 10:
                this.ExportToSvg = ((Fluent.Button)(target));
                return;

            case 11:
                this.ClickEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;

            case 12:
                this.openpdfile = ((Fluent.Button)(target));

            #line 335 "..\..\..\MainWindow.xaml"
                this.openpdfile.Click += new System.Windows.RoutedEventHandler(this.openpdfile_Click);

            #line default
            #line hidden
                return;

            case 13:
                this.openqxfile = ((Fluent.Button)(target));

            #line 336 "..\..\..\MainWindow.xaml"
                this.openqxfile.Click += new System.Windows.RoutedEventHandler(this.openqxfile_Click);

            #line default
            #line hidden
                return;

            case 14:
                this.openbjfile = ((Fluent.Button)(target));

            #line 337 "..\..\..\MainWindow.xaml"
                this.openbjfile.Click += new System.Windows.RoutedEventHandler(this.openbjfile_Click);

            #line default
            #line hidden
                return;

            case 15:
                this.modifycdldata = ((Fluent.Button)(target));
                return;

            case 16:
                this.autofitcdldata = ((Fluent.Button)(target));
                return;

            case 17:
                this.showcdldata = ((Fluent.ToggleButton)(target));
                return;

            case 18:
                this.checkdatasign = ((Fluent.Button)(target));

            #line 345 "..\..\..\MainWindow.xaml"
                this.checkdatasign.Click += new System.Windows.RoutedEventHandler(this.checkdatasign_Click);

            #line default
            #line hidden
                return;

            case 19:
                this.checklogic = ((Fluent.Button)(target));

            #line 346 "..\..\..\MainWindow.xaml"
                this.checklogic.Click += new System.Windows.RoutedEventHandler(this.checklogic_Click);

            #line default
            #line hidden
                return;

            case 20:
                this.opentemppdfile = ((Fluent.Button)(target));

            #line 349 "..\..\..\MainWindow.xaml"
                this.opentemppdfile.Click += new System.Windows.RoutedEventHandler(this.opentemppdfile_Click);

            #line default
            #line hidden
                return;

            case 21:
                this.opentempqxfile = ((Fluent.Button)(target));

            #line 350 "..\..\..\MainWindow.xaml"
                this.opentempqxfile.Click += new System.Windows.RoutedEventHandler(this.opentempqxfile_Click);

            #line default
            #line hidden
                return;

            case 22:
                this.opentempbjfile = ((Fluent.Button)(target));

            #line 351 "..\..\..\MainWindow.xaml"
                this.opentempbjfile.Click += new System.Windows.RoutedEventHandler(this.opentempbjfile_Click);

            #line default
            #line hidden
                return;

            case 23:
                this.changeS = ((Fluent.Button)(target));

            #line 356 "..\..\..\MainWindow.xaml"
                this.changeS.Click += new System.Windows.RoutedEventHandler(this.changeS_Click);

            #line default
            #line hidden
                return;

            case 24:
                this.changeX = ((Fluent.Button)(target));

            #line 357 "..\..\..\MainWindow.xaml"
                this.changeX.Click += new System.Windows.RoutedEventHandler(this.changeX_Click);

            #line default
            #line hidden
                return;

            case 25:
                this.changeSX = ((Fluent.Button)(target));

            #line 358 "..\..\..\MainWindow.xaml"
                this.changeSX.Click += new System.Windows.RoutedEventHandler(this.changeSX_Click);

            #line default
            #line hidden
                return;

            case 26:
                this.changemerge = ((Fluent.Button)(target));

            #line 361 "..\..\..\MainWindow.xaml"
                this.changemerge.Click += new System.Windows.RoutedEventHandler(this.changemerge_Click);

            #line default
            #line hidden
                return;

            case 27:
                this.exportoto = ((Fluent.Button)(target));
                return;

            case 28:
                this.ShowDataRibbonTabItem = ((Fluent.RibbonTabItem)(target));
                return;

            case 29:
                this.LineDataRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 30:
                this.LoadPDToggleButton = ((Fluent.ToggleButton)(target));
                return;

            case 31:
                this.LoadQXToggleButton = ((Fluent.ToggleButton)(target));
                return;

            case 32:
                this.LoadCZToggleButton = ((Fluent.ToggleButton)(target));
                return;

            case 33:
                this.PositionToggleButton = ((Fluent.ToggleButton)(target));
                return;

            case 34:
                this.SingleRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 35:
                this.loadxhdataButton = ((Fluent.ToggleButton)(target));
                return;

            case 36:
                this.loadxhsdatabutton = ((Fluent.ToggleButton)(target));
                return;

            case 37:
                this.ModifyStationsignalButton = ((Fluent.Button)(target));
                return;

            case 38:
                this.signalDataRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 39:
                this.creatnewsignalButton = ((Fluent.Button)(target));
                return;

            case 40:
                this.opensignalButton = ((Fluent.Button)(target));
                return;

            case 41:
                this.SaveStationsignalButton = ((Fluent.Button)(target));
                return;

            case 42:
                this.SaveothersignalButton = ((Fluent.Button)(target));
                return;

            case 43:
                this.exportSplitButton = ((Fluent.SplitButton)(target));
                return;

            case 44:
                this.CheckDataRibbonTabItem = ((Fluent.RibbonTabItem)(target));
                return;

            case 45:
                this.MuRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 46:
                this.BulitTrainbutton = ((Fluent.Button)(target));
                return;

            case 47:
                this.CheckUmDisbutton = ((Fluent.Button)(target));
                return;

            case 48:
                this.ModifyXinhaoRibbonTabItem = ((Fluent.RibbonTabItem)(target));
                return;

            case 49:
                this.DetailRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 50:
                this.LiChenTextBox = ((Fluent.TextBox)(target));
                return;

            case 51:
                this.LxTextBox = ((Fluent.TextBox)(target));
                return;

            case 52:
                this.BhTextBox = ((Fluent.TextBox)(target));
                return;

            case 53:
                this.ModifyRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 54:
                this.distenceSpinner = ((Fluent.Spinner)(target));
                return;

            case 55:
                this.CommitButton = ((Fluent.Button)(target));
                return;

            case 56:
                this.ModifySignalButton = ((Fluent.Button)(target));
                return;

            case 57:
                this.DeleteSignalButton = ((Fluent.Button)(target));
                return;

            case 58:
                this.ModifyQjRibbonTabItem = ((Fluent.RibbonTabItem)(target));
                return;

            case 59:
                this.QjInfoRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 60:
                this.QidianTextBox = ((Fluent.TextBox)(target));
                return;

            case 61:
                this.LengthTextBox = ((Fluent.TextBox)(target));
                return;

            case 62:
                this.ModifyQjRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 63:
                this.PartLengthTextBox = ((Fluent.TextBox)(target));
                return;

            case 64:
                this.DivSpinner = ((Fluent.Spinner)(target));
                return;

            case 65:
                this.DivButton = ((Fluent.Button)(target));
                return;

            case 66:
                this.InsertButton = ((Fluent.Button)(target));
                return;

            case 67:
                this.InsertDFXButton = ((Fluent.Button)(target));
                return;

            case 68:
                this.ModifyDfxRibbonTabItem = ((Fluent.RibbonTabItem)(target));
                return;

            case 69:
                this.DfxInfoRibbonGroupBox = ((Fluent.RibbonGroupBox)(target));
                return;

            case 70:
                this.ModifyDianfxButton = ((Fluent.Button)(target));
                return;

            case 71:
                this.DeleteDianfxButton = ((Fluent.Button)(target));
                return;

            case 72:
                this.QujianRibbonContextualTabGroup = ((Fluent.RibbonContextualTabGroup)(target));
                return;

            case 73:
                this.XinhaoContextualTabGroup = ((Fluent.RibbonContextualTabGroup)(target));
                return;

            case 74:
                this.DianFxContextualTabGroup = ((Fluent.RibbonContextualTabGroup)(target));
                return;

            case 75:
                this.infoboxpanel = ((System.Windows.Controls.WrapPanel)(target));
                return;

            case 76:
                this.DataLlistBox = ((System.Windows.Controls.ListBox)(target));
                return;

            case 77:
                this.statugrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 78:
                this.ProcessLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 79:
                this.ProgressBar = ((System.Windows.Controls.ProgressBar)(target));
                return;
            }
            this._contentLoaded = true;
        }
        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
        }
        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 SILVERLIGHT
            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);
        }
예제 #16
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Window = ((Inter_face.DianFXWindow)(target));
                return;

            case 2:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.OpGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.CancelButton = ((System.Windows.Controls.Button)(target));
                return;

            case 5:
                this.OkButton = ((System.Windows.Controls.Button)(target));
                return;

            case 6:
                this.LeftGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 7:
                this.StartTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 8:
                this.LeftEdgeTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 9:
                this.StartDisTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 10:
                this.MidGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 11:
                this.PartITextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 12:
                this.PartIITextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.PlusTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 14:
                this.HatTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 15:
                this.RightGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 16:
                this.RightEdgeTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 17:
                this.EndTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 18:
                this.EndDisTextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 19:
                this.NameGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 20:
                this.NameTextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 21:
                this.NametextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 22:
                this.LeftEdgeDisTextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 23:
                this.RightEdgeDisTextBox = ((System.Windows.Controls.TextBox)(target));
                return;

            case 24:
                this.RightSigntextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 25:
                this.LeftSigntextBlock = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 26:
                this.cdlComboBox = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 27:
                this.SelectionChangedEventToCommand = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #17
0
        public void TestEnableCommandAndRectangle()
        {
            var trigger = new EventToCommand
            {
                MustToggleIsEnabledValue = true
            };

#if DOTNET
            var rectangle = new Rectangle
            {
                IsEnabled = false
            };
#else
            var rectangle = new Rectangle();
#endif

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

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

            vm.EnableToggledCommand = true;

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

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

            trigger.Invoke();
            Assert.IsTrue(vm.CommandExecuted);
        }
예제 #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);
        }
        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 SILVERLIGHT
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

#if !SILVERLIGHT
            Assert.IsFalse(rectangle.IsEnabled);
#endif
            trigger.Invoke();
            Assert.IsFalse(vm.CommandExecuted);
        }
예제 #20
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.bynLogShow = ((System.Windows.Controls.Button)(target));
     return;
     case 2:
     this.lstMessages = ((System.Windows.Controls.ListBox)(target));
     return;
     case 3:
     this.lstUsers = ((System.Windows.Controls.ListBox)(target));
     return;
     case 4:
     this.txtMessage = ((System.Windows.Controls.TextBox)(target));
     return;
     case 5:
     this.btnSend = ((System.Windows.Controls.Button)(target));
     return;
     case 6:
     this.ClosedWin = ((GalaSoft.MvvmLight.Command.EventToCommand)(target));
     return;
     }
     this._contentLoaded = true;
 }