A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/MyToolkit/Core/wiki/RelayCommand below:

RelayCommand · RicoSuter/MyToolkit Wiki · GitHub

See also AsyncRelayCommand

The RelayCommand class implements the interface ICommand which can be used in various XAML elements, for example the Button control. The following listing shows sample XAML which binds to commands:

<Button Command="{Binding CreatePersonCommand}" />
<Button Command="{Binding DeletePersonCommand}" 
        CommandParameter="{Binding Person}" />

And the view model with the commands:

public MyViewModel
{
    public ICommand CreatePersonCommand { get; private set; }
    public ICommand DeletePersonCommand { get; private set; }

    public MyViewModel()
    {
        CreatePerdonCommand = new RelayCommand(CreatePerson);
        DeletePersonCommand = new RelayCommand<Person>(
            DeletePerson, person => person != null);
    }
 
    public void CreatePerson()
    {
        // your code here
    }
 
    public void DeletePerson(Person person)
    {
        // your code here
    }
}

The RelayCommand without parameter (non-generic) also implements INotifyPropertyChanged for the CanExecute property.

To manually tell the GUI that the can execute state has changed, simply call the RaiseCanExecuteChanged() method:

DeletePersonCommand.RaiseCanExecuteChanged();

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4