当前位置: 首页>>代码示例>>C#>>正文


C# DelegateCommand.CanExecute方法代码示例

本文整理汇总了C#中DelegateCommand.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.CanExecute方法的具体用法?C# DelegateCommand.CanExecute怎么用?C# DelegateCommand.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DelegateCommand的用法示例。


在下文中一共展示了DelegateCommand.CanExecute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RaiseCanExecuteChangedTest

        public void RaiseCanExecuteChangedTest()
        {
            var executed = false;
            var canExecute = false;
            var command = new DelegateCommand(() => executed = true, () => canExecute);
            
            Assert.IsFalse(command.CanExecute(null));
            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());
            
            Assert.IsFalse(executed);
        }
开发者ID:jbe2277,项目名称:waf,代码行数:14,代码来源:DelegateCommandTest.cs

示例2: ExecuteTest3

        public void ExecuteTest3()
        {
            var executed = false;
            var canExecute = true;
            var command = new DelegateCommand(() => executed = true, () => canExecute);

            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executed);

            executed = false;
            canExecute = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executed);
        }
开发者ID:jbe2277,项目名称:waf,代码行数:16,代码来源:DelegateCommandTest.cs

示例3: WhenCanExecuteParameterIsNull_ThenExecutes

        public void WhenCanExecuteParameterIsNull_ThenExecutes()
        {
            var command = new DelegateCommand(() => { }, () => true);

            var can = command.CanExecute(null);

            Assert.True(can);
        }
开发者ID:netfx,项目名称:extensions,代码行数:8,代码来源:DelegateCommandSpec.cs

示例4: ExecuteNoPredicateWithNull

 public void ExecuteNoPredicateWithNull()
 {
     bool called = false;
     DelegateCommand cmd = new DelegateCommand((o) => called = true);
     Assert.IsTrue(cmd.CanExecute(null), "Command should always be able to execute when no predicate is supplied.");
     cmd.Execute(null);
     Assert.IsTrue(called, "Command did not run supplied Action.");
 }
开发者ID:jetlive,项目名称:skiaming,代码行数:8,代码来源:DelegateCommandTests.cs

示例5: CanExecuteReturnsResultOfTheFunctionIfItWasGiven

        public void CanExecuteReturnsResultOfTheFunctionIfItWasGiven()
        {
            _sut = new DelegateCommand(d => executed = true, d => false);

            var result = _sut.CanExecute(null);

            Assert.IsFalse(result);
        }
开发者ID:reflectiondm,项目名称:FileWizard,代码行数:8,代码来源:DelegateCommandTests.cs

示例6: CanExectue_WithoutCanExecute_True

        public void CanExectue_WithoutCanExecute_True()
        {
            var subject = new DelegateCommand(() => { });

            var result = subject.CanExecute();

            Assert.IsTrue(result);
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:8,代码来源:DelegateCommandTest.cs

示例7: CanExecute_NoCanExecuteDelegateDefined_ReturnsTrue

		public void CanExecute_NoCanExecuteDelegateDefined_ReturnsTrue ()
		{
			Action<object> execute = delegate { };
			var command = new DelegateCommand (execute);

			bool result = command.CanExecute (null);

			Assert.IsTrue (result);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:9,代码来源:DelegateCommandTests.cs

示例8: CanExecuteDelegateWorks

        public void CanExecuteDelegateWorks()
        {
            Predicate<object> predicate = (o) =>
                {
                    if (o is bool)
                        return (bool)o;
                    else
                        return false;
                };
            Action<object> action = o => { };

            bool canExecute = false;
            ICommand delegateCommand = new DelegateCommand(action, predicate);
            Assert.IsFalse(delegateCommand.CanExecute(canExecute));

            canExecute = true;
            Assert.IsTrue(delegateCommand.CanExecute(canExecute));
        }
开发者ID:ryanbutcher06,项目名称:MVVMSupport,代码行数:18,代码来源:DelegateCommandTests.cs

示例9: CanExecute

        public void CanExecute()
        {
            bool b = false;
            int i = 0;

            Action<int> execute = (param => i = i + param);
            Func<int, bool> predicate = (param => b);
            var command = new DelegateCommand<int>(execute, predicate);

            Assert.IsFalse(((ICommand)command).CanExecute(i));
            Assert.IsFalse(command.CanExecute(i));
            b = true;
            Assert.IsTrue(((ICommand)command).CanExecute(i));
            Assert.IsTrue(command.CanExecute(i));
            b = false;
            Assert.IsFalse(((ICommand)command).CanExecute(i));
            Assert.IsFalse(command.CanExecute(i));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:18,代码来源:DelegateCommandOfTTest.cs

示例10: ExecuteTest2

        public void ExecuteTest2()
        {
            var executed = false;
            object commandParameter = null;
            var command = new DelegateCommand(parameter =>
            {
                executed = true;
                commandParameter = parameter;
            });

            var obj = new object();
            Assert.IsTrue(command.CanExecute(null));
            Assert.IsTrue(command.CanExecute(obj));

            command.Execute(obj);
            Assert.IsTrue(executed);
            Assert.AreSame(obj, commandParameter);
        }
开发者ID:jbe2277,项目名称:waf,代码行数:18,代码来源:DelegateCommandTest.cs

示例11: CanExecuteReturnsTrueWithouthCanExecuteDelegate

        public void CanExecuteReturnsTrueWithouthCanExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute);

            bool retVal = command.CanExecute(null);

            Assert.AreEqual(true, retVal);
        }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:9,代码来源:DelegateCommandFixture.cs

示例12: CanExecute

        public void CanExecute()
        {
            bool b = false;
            int i = 0;

            Action execute = (() => i++);
            Func<bool> predicate = (() => b);
            var command = new DelegateCommand(execute, predicate);

            object dummy = new object();
            Assert.IsFalse(((ICommand)command).CanExecute(dummy));
            Assert.IsFalse(command.CanExecute());
            b = true;
            Assert.IsTrue(((ICommand)command).CanExecute(dummy));
            Assert.IsTrue(command.CanExecute());
            b = false;
            Assert.IsFalse(((ICommand)command).CanExecute(dummy));
            Assert.IsFalse(command.CanExecute());
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:19,代码来源:DelegateCommandTest.cs

示例13: CanExecute_CanExecuteDelegateDefinedToReturnFalse_ReturnsFalse

        public void CanExecute_CanExecuteDelegateDefinedToReturnFalse_ReturnsFalse()
        {
            Action<object> execute = delegate { };
            Predicate<object> canExecute = delegate { return false; };
            var command = new DelegateCommand(execute, canExecute);

            bool result = command.CanExecute(null);

            Assert.IsFalse(result);
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:10,代码来源:DelegateCommandTests.cs

示例14: ShouldReturnTrueIfConstructedWithNull

            public void ShouldReturnTrueIfConstructedWithNull()
            {
                bool methodCalled = false;
                DelegateCommand testCommand = new DelegateCommand((param) => methodCalled = true);

                testCommand.Execute(null);
                Assert.IsTrue(methodCalled);

                Assert.IsTrue(testCommand.CanExecute(null));
            }
开发者ID:blattodephobia,项目名称:ExperianOfficeArangement,代码行数:10,代码来源:DelegateCommandTests.cs

示例15: CanExecuteCallsPassedInCanExecuteDelegate

        public void CanExecuteCallsPassedInCanExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute, handlers.CanExecute);
            object parameter = new object();

            handlers.CanExecuteReturnValue = true;
            bool retVal = command.CanExecute(parameter);

            Assert.AreSame(parameter, handlers.CanExecuteParameter);
            Assert.AreEqual(handlers.CanExecuteReturnValue, retVal);
        }
开发者ID:ValdimarThor,项目名称:Prism,代码行数:12,代码来源:DelegateCommandFixture.cs


注:本文中的DelegateCommand.CanExecute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。