Last active
August 29, 2015 14:07
-
-
Save EifelMono/13d1e66b7108efc8e685 to your computer and use it in GitHub Desktop.
WPF CommandHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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