|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace TestTreeViewWithRightBarView.ViewModel
{
public class DelegateCommand : ICommand
{
#region Helper Objects
public delegate void SimpleEventHandler();
#endregion
#region Events
public event EventHandler CanExecuteChanged;
#endregion
#region Members
SimpleEventHandler m_Handler;
bool m_bEnabled;
#endregion
#region Methods
#region Ctor
public DelegateCommand(SimpleEventHandler handler)
{
this.m_Handler = handler;
m_bEnabled = true;
}
#endregion
private void OnCanExecuteChanged()
{
if (this.CanExecuteChanged != null)
{
this.CanExecuteChanged(this, EventArgs.Empty);
}
}
bool ICommand.CanExecute(object arg)
{
return this.IsEnabled;
}
void ICommand.Execute(object arg)
{
this.m_Handler();
}
public bool IsEnabled
{
get
{
return this.m_bEnabled;
}
set
{
this.m_bEnabled = value;
this.OnCanExecuteChanged();
}
}
#endregion
}
}
|
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.