本文整理汇总了C#中RelayCommand.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# RelayCommand.CanExecute方法的具体用法?C# RelayCommand.CanExecute怎么用?C# RelayCommand.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RelayCommand
的用法示例。
在下文中一共展示了RelayCommand.CanExecute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecuteUsesPredicateIfSet
public void CanExecuteUsesPredicateIfSet()
{
var canExecute = false;
// ReSharper disable once AccessToModifiedClosure
var command = new RelayCommand(o => { }, o => canExecute);
command.CanExecute(null).Should().BeFalse();
canExecute = true;
command.CanExecute(null).Should().BeTrue();
}
示例2: RelayCommand_CanExecute_CanNotExecuteWhenFalse
public void RelayCommand_CanExecute_CanNotExecuteWhenFalse()
{
var count = 0;
var cmd = new RelayCommand(o => count = (int) o, () => false);
Assert.IsFalse(cmd.CanExecute());
}
示例3: RelayCommand_CanExecute_CanExecuteWhenTrue
public void RelayCommand_CanExecute_CanExecuteWhenTrue()
{
var count = 0;
var cmd = new RelayCommand(o => count = (int) o, () => true);
Assert.IsTrue(cmd.CanExecute());
}
示例4: Given_CanExecuteDelegate_When_ICallCanExecute_ItReturnsCorrectValue
public void Given_CanExecuteDelegate_When_ICallCanExecute_ItReturnsCorrectValue()
{
var expected = new Random().Next(0, 2) == 1;
var sut = new RelayCommand<object>(Delegate1, o => expected);
Assert.AreEqual(expected, sut.CanExecute(null));
}
示例5: CanExecuteIsTrueWhenThereIsNoPredicate
public void CanExecuteIsTrueWhenThereIsNoPredicate()
{
_relayCommand = new RelayCommand(OnActionCalled);
var actual = _relayCommand.CanExecute(null);
Assert.IsTrue(actual);
}
示例6: RelayCommand_Construction_WithoutCanExecuteCanActuallyExecute
public void RelayCommand_Construction_WithoutCanExecuteCanActuallyExecute()
{
var count = 0;
var cmd = new RelayCommand(o => count = (int) o);
if (cmd.CanExecute())
cmd.Execute(15);
Assert.AreEqual(15, count);
}
示例7: CanExecuteIsTrueIfNotSet
public void CanExecuteIsTrueIfNotSet()
{
var command = new RelayCommand(o => { });
command.CanExecute(null).Should().BeTrue();
}
示例8: AddCommandToService
private void AddCommandToService(OleMenuCommandService service, Guid cmdSet, int cmdId, RelayCommand relayCommand)
{
var commandId = new CommandID(cmdSet, cmdId);
var menuCommand = new OleMenuCommand((sender, args) =>
{
relayCommand.Execute(null);
}, commandId);
menuCommand.BeforeQueryStatus += (sender, args) =>
{
menuCommand.Enabled = relayCommand.CanExecute(null);
};
service.AddCommand(menuCommand);
}
示例9: Given_NoCanExecute_When_AskedForCanExecute_CanExecuteReturnsTrue
public void Given_NoCanExecute_When_AskedForCanExecute_CanExecuteReturnsTrue()
{
var sut = new RelayCommand<object>(Delegate1);
Assert.IsTrue(sut.CanExecute(null));
}