title: How to Bind a Command in WPF
body: <p>Sometimes we used complex ways so many times, we forgot the simplest ways to do the task.</p>
  
  <p>I know how to do command binding, but i always use same approach. </p>
  
  <p>Create a class that implements ICommand interface and from the view model i create new instance of that class and binding works like a charm.</p>
  
  <p>This is the code that i used for command binding</p>
  
  <pre><code> public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          DataContext = this;            
          testCommand = new MeCommand(processor);
      }
  
      ICommand testCommand;
  
      public ICommand test
      {
          get { return testCommand; }
      }
      public void processor()
      {
          MessageBox.Show("hello world");
      }
  }
  
  public class MeCommand : ICommand
  {
      public delegate void ExecuteMethod();
      private ExecuteMethod meth;
      public MeCommand(ExecuteMethod exec)
      {
          meth = exec;
      }
  
      public bool CanExecute(object parameter)
      {
          return false;
      }
  
      public event EventHandler CanExecuteChanged;
  
      public void Execute(object parameter)
      {
          meth();
      }
  }
  </code></pre>
  
  <p>But i want to know the basic way to do this, no third party dll no new class creation. Do this simple command binding using a single class. Actual class implements from ICommand interface and do the work.</p>