Skip to content

Instantly share code, notes, and snippets.

@EifelMono
Last active August 29, 2015 14:07
Show Gist options
  • Save EifelMono/13d1e66b7108efc8e685 to your computer and use it in GitHub Desktop.
Save EifelMono/13d1e66b7108efc8e685 to your computer and use it in GitHub Desktop.
WPF CommandHandler
// Command xCommand = new CommandHandler(() => DoX());
class CommandHandler : ICommand
{
private Action m_Action;
public CommandHandler(Action action)
{
m_Action = action;
}
public bool CanExecute(object parameter)
{
return Enabled;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
m_Action();
}
#region property Enabled
private bool m_Enabled = true;
public bool Enabled
{
get { return m_Enabled; }
set
{
if (m_Enabled != value)
{
m_Enabled = value;
if (CanExecuteChanged != null)
Application.Current.Dispatcher.Invoke(new Action(() => CanExecuteChanged(this, null)));
}
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment