Czy ktoś wie, jak przekazać parametry do Command
przy użyciu CommandHandler
? Załóżmy, że chciałbym przekazać ciąg sztywno zakodowaną wartość z XAML. Wiem, jak przejść z XAML, ale nie jak sobie z tym poradzić w kodzie MVVM. Poniższy kod działa poprawnie, jeśli nie ma potrzeby przekazywania jakichkolwiek parametrów.Przesyłanie parametrów do polecenia MVVM
public ICommand AttachmentChecked
{
get
{
return _attachmentChecked ?? (_attachmentChecked = new CommandHandler(() => ExecuteAttachmentChecked(), CanExecuteAttachmentChecked()));
}
}
private void ExecuteAttachmentChecked()
{
}
private bool CanExecuteAttachmentChecked()
{
return true;
}
CommandHandler:
public class CommandHandler : ICommand
{
private Action _action;
private bool _canExecute;
public CommandHandler(Action action, bool canExecute)
{
_action = action;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_action();
}
}