本文整理汇总了C#中GalaSoft.MvvmLight.Command.RelayCommand.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# RelayCommand.CanExecute方法的具体用法?C# RelayCommand.CanExecute怎么用?C# RelayCommand.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GalaSoft.MvvmLight.Command.RelayCommand
的用法示例。
在下文中一共展示了RelayCommand.CanExecute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecuteTest
public void CanExecuteTest()
{
var command = new RelayCommand<string>(p =>
{
},
p => p == "CanExecute");
Assert.AreEqual(true, command.CanExecute("CanExecute"));
Assert.AreEqual(false, command.CanExecute("Hello"));
}
示例2: CanExecuteTest
public void CanExecuteTest()
{
var canExecute = true;
var command = new RelayCommand(() =>
{
},
() => canExecute);
Assert.AreEqual(true, command.CanExecute(null));
canExecute = false;
Assert.AreEqual(false, command.CanExecute(null));
}
示例3: CanExecuteTestNull
public void CanExecuteTestNull()
{
var command = new RelayCommand(() =>
{
});
Assert.AreEqual(true, command.CanExecute(null));
}
示例4: CanExecuteTestNull
public void CanExecuteTestNull()
{
var command = new RelayCommand<string>(p =>
{
});
Assert.AreEqual(true, command.CanExecute("Hello"));
}
示例5: CanExecuteTestInvalidParameterType
public void CanExecuteTestInvalidParameterType()
{
var command = new RelayCommand<string>(p =>
{
},
p => p == "CanExecute");
command.CanExecute(DateTime.Now);
}
示例6: CanExecuteTestNullParameter
public void CanExecuteTestNullParameter()
{
var command = new RelayCommand<string>(p =>
{
},
p => false);
Assert.AreEqual(false, command.CanExecute(null));
var command2 = new RelayCommand<string>(p =>
{
},
p => true);
Assert.AreEqual(true, command2.CanExecute(null));
}
示例7: MainViewModel
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel(IDataService dataService)
{
_dataService = dataService;
Users = new ObservableCollection<User>();
ReadAllUsersCommand = new RelayCommand(GetUsers);
//Execute ReadAllUsersCommand to display all users on the main window when the application launches
if (ReadAllUsersCommand.CanExecute(null))
ReadAllUsersCommand.Execute(null);
SearchUsersCommand = new RelayCommand(SearchUsers);
SendUserCommand = new RelayCommand(SendUser);
ReceiveRefreshUsersMessage();
}
示例8: CanExecuteTestInvalidParameterType
public void CanExecuteTestInvalidParameterType()
{
var command = new RelayCommand<string>(
p =>
{
},
p => p == "CanExecute");
try
{
command.CanExecute(DateTime.Now);
Assert.Fail("InvalidCastException was not thrown");
}
catch (InvalidCastException)
{
}
}
示例9: TestCanExecuteWithInvalidParameterType
public void TestCanExecuteWithInvalidParameterType()
{
var command = new RelayCommand<string>(
p =>
{
},
p => p == "CanExecute");
var result = command.CanExecute(DateTime.Now);
Assert.IsFalse(result);
}