|
using System;
using System.Windows.Input;
using System.Windows;
namespace ModificationTrackingUtility.ViewModels
{
public class DelegateCommand<T> : ICommand
{
private readonly Predicate<T> canExecute;
private readonly Action<T> execute;
public event EventHandler CanExecuteChanged;
public DelegateCommand(Action<T> execute)
: this(execute, null)
{
}
public DelegateCommand(Action<T> execute,
Predicate<T> canExecute)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
if (this.canExecute == null)
{
return true;
}
return this.canExecute((T)parameter);
}
public void Execute(object parameter)
{
execute((T)parameter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}
public class SenderParameter
{
public RoutedEventArgs EArgs { get; set; }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.