Существует несколько примеров того, как определить RelayCommand в ViewModel :
Опция 1 ( lazy ):
/// <summary>
/// Gets the LogOnCommand.
/// </summary>
/// <value>The LogOnCommand.</value>
public RelayCommand<LogOnUser> LogOnCommand
{
get
{
if (this.logOnCommand == null)
{
this.logOnCommand = new RelayCommand<LogOnUser>(
action =>
{
// Action code...
},
g => g != null);
}
return this.logOnCommand;
}
}
Вариант 2 (в конструкторе )
/// <summary>
/// Initializes a new instance of the <see cref="LogOnFormViewModel"/> class.
/// </summary>
public LogOnFormViewModel()
{
this.logOnCommand = new RelayCommand<LogOnUser>(
action =>
{
// Action code...
},
g => g != null);
}
/// <summary>
/// Gets the LogOnCommand.
/// </summary>
/// <value>The LogOnCommand.</value>
public RelayCommand<LogOnUser> LogOnCommand {get; private set;}
Каков наилучший / четкий дизайн?