public class ViewModel : INotifyPropertyChanged
{
// INotifyPropertyChanged implementation
// Properties implementation
public ViewModel()
{
ActionCommand = new MyCommand();
ActionCommand.CanExecuteFunc = obj => true;
ActionCommand.ExecuteFunc = MyActionFunc;
}
public void MyActionFunc(object parameter)
{
//Operations
}
}
public class MyCommand : ICommand
{
public Predicate<object> CanExecuteFunc{ get; set; }
public Action<object> ExecuteFunc { get; set; }
public bool CanExecute(object parameter)
{
return CanExecuteFunc(parameter);
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
ExecuteFunc(parameter);
}
}
XAML file{
// INotifyPropertyChanged implementation
// Properties implementation
public ViewModel()
{
ActionCommand = new MyCommand();
ActionCommand.CanExecuteFunc = obj => true;
ActionCommand.ExecuteFunc = MyActionFunc;
}
public void MyActionFunc(object parameter)
{
//Operations
}
}
public class MyCommand : ICommand
{
public Predicate<object> CanExecuteFunc{ get; set; }
public Action<object> ExecuteFunc { get; set; }
public bool CanExecute(object parameter)
{
return CanExecuteFunc(parameter);
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
ExecuteFunc(parameter);
}
}
<Button Command="{Binding Path=ActionCommand}"
CommandParameter="ParameterValue" />