-
Notifications
You must be signed in to change notification settings - Fork 1
Commads
ekral edited this page Nov 6, 2017
·
14 revisions
- Ukázka zjednodušené verze RelayCommandu, která jen volá metodu bez parametru pomocí delegáta.
<Button Command="{Binding CommandNovyStudent}" Content="Vytvoř nového studenta"/>private Action _action;
public void Execute(object parameter)
{
_action?.Invoke();
}public class Data : ViewModelBase
{
public RelayCommand CommandNovyStudent { get; set; }
public Data()
{
CommandNovyStudent = new RelayCommand(OnNovyStudent);
}
private void OnNovyStudent()
{
// Pridani noveho studenta
}
}- Ukázka použití RelayCommandu atributu CommandParameter pro předávání parametrů
<Button Content="Přičti 1" Command="{Binding CommandZmena}" CommandParameter="1" />private Action<object> _action;
public void Execute(object parameter)
{
_action?.Invoke(parameter);
}