Click or drag to resize
DelegateCommand Class
Inheritance Hierarchy

Namespace: DW.SharpTools
Assembly: DW.SharpTools (in DW.SharpTools.dll) Version: 2.4.0.0 (2.4.0.0)
Syntax
C#
public sealed class DelegateCommand : DelegateCommandBase

The DelegateCommand type exposes the following members.

Constructors
  NameDescription
Public methodDelegateCommand(Action)
Initializes a new instance of the DW.SharpTools.DelegateCommand class with the execute delegate.
Public methodDelegateCommand(FuncBoolean, Action)
Initializes a new instance of the DW.SharpTools.DelegateCommand class with the can execute and execute delegates.
Top
Methods
  NameDescription
Public methodCanExecute
Calls and returns the result of the can execute delegate. See CanExecute(Object).
Public methodExecute
Calls the execute delegate. See Execute(Object).
Top
Examples
C#
public class MainViewModel : ObservableObject
{
    public MainViewModel()
    {
        SimpleDemoCommand = new DelegateCommand(CanSimpleDemo, SimpleDemo);
    }

    public DelegateCommand SimpleDemoCommand { get; private set; }

    private bool CanSimpleDemo()
    {
        //Return true if the command can be executed; otherwise false
        return true;
    }

    private void SimpleDemo()
    {
        //Do something
    }
}

public class MainViewModel : ObservableObject
{
    public MainViewModel()
    {
        ParameteredDemoCommand = new DelegateCommand<string>(CanParameteredDemo, ParameteredDemo);
    }

    public DelegateCommand<string> ParameteredDemoCommand { get; private set; }

    private bool CanParameteredDemo(string parameter)
    {
        //Return true if the command can be executed; otherwise false
        return true;
    }

    private void ParameteredDemo(string parameter)
    {
        //Do something with the passed parameter
    }
}
XAML
<Button Content="Simple Demo" Command="{Binding SimpleDemoCommand}" />

<Button Content="Parametered Demo" Command="{Binding ParameteredDemoCommand}" CommandParameter="The Parameter" />
See Also