1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #region (c) 2019 Gilles Macabies All right reserved
- // Author : Gilles Macabies
- // Solution : DataGridFilter
- // Projet : DataGridFilter
- // File : DelegateCommand.cs
- // Created : 05/11/2019
- #endregion
- using System;
- using System.Windows.Input;
- namespace DemoApplication.ModelView
- {
- /// <summary>
- /// DelegateCommand borrowed from
- /// http://www.wpftutorial.net/DelegateCommand.html
- /// </summary>
- public class DelegateCommand : ICommand
- {
- private readonly Predicate<object> _canExecute;
- private readonly Action<object> _execute;
- public DelegateCommand(Action<object> execute,
- Predicate<object> canExecute = null)
- {
- _execute = execute;
- _canExecute = canExecute;
- }
- public void RaiseCanExecuteChanged()
- {
- CanExecuteChanged?.Invoke(this, EventArgs.Empty);
- }
- #region ICommand Members
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter)
- {
- return _canExecute == null || _canExecute(parameter);
- }
- public void Execute(object parameter)
- {
- _execute(parameter);
- }
- #endregion
- }
- }
|