using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace RealTimeGraphX
{
///
/// Represents a graph relay command.
///
///
public class GraphCommand : ICommand
{
private Action _action;
private Func _canExecute;
///
/// Initializes a new instance of the class.
///
/// The action.
/// The can execute.
public GraphCommand(Action action, Func canExecute)
{
_action = action;
_canExecute = canExecute;
}
///
/// Initializes a new instance of the class.
///
/// The action.
public GraphCommand(Action action) : this(action, null)
{
}
///
/// Defines the method that determines whether the command can execute in its current state.
///
/// Data used by the command. If the command does not require data to be passed, this object can be set to null.
///
/// true if this command can be executed; otherwise, false.
///
public bool CanExecute(object parameter)
{
if (_canExecute != null)
{
return _canExecute();
}
return true;
}
///
/// Defines the method to be called when the command is invoked.
///
/// Data used by the command. If the command does not require data to be passed, this object can be set to null.
public void Execute(object parameter)
{
_action();
}
///
/// Raises the can execute changed event.
///
public void RaiseCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, new EventArgs());
}
///
/// Occurs when changes occur that affect whether or not the command should execute.
///
///
public event EventHandler CanExecuteChanged;
}
}