title: Bind command in WPF using MVVM
body: <p>I am learning <strong>MVVM</strong> and <strong>WPF</strong>. I have a <code>xaml</code> file in my project and which has a simple click event handler in the code behind.</p>
  
  <p>Now I want to do the same in <strong>MVVM</strong>. I read a lot of articles and also read many answers in sof. But still unable to do this.</p>
  
  <p>Can anyone please give a simple example in which a button <strong>click</strong> event is done in <strong>MVVM</strong>.</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>&lt;Window x:Class="WhiteBalance.BaseCalWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:uc="clr-namespace:NumberUpDownControl;assembly=NumberUpDownControl"
          xmlns:viewn="clr-namespace:WhiteBalance.ViewModels"
          Title="RefImgSettingWindow"  Height="900" Width="1000" ResizeMode="NoResize" 
          BorderThickness="4"&gt;
      &lt;Window.Resources&gt;
          &lt;viewn:DashBoardViewModel x:Key="demokey"&gt;&lt;/viewn:DashBoardViewModel&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid x:Name="gdParent" DataContext="{StaticResource demokey}"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="490" /&gt;
              &lt;ColumnDefinition Width="488*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="300" /&gt;
              &lt;RowDefinition Height="300" /&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;StackPanel Grid.Row="0" Grid.Column="0"&gt;
              &lt;Label Content="{Binding Path=NAME,Mode=TwoWay}" Height="28" Name="lblTest" /&gt;
              &lt;Button Content="Capture" Height="23" Name="btnCapture" Width="75" Command="{Binding Path=SaveCommand}"
                               Canvas.Left="94" Canvas.Top="254" /&gt;
  
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  
  namespace WhiteBalance.ViewModels
  {
      public class DashBoardViewModel: ObservableObject
      {
          private string _name = "dsqdasd";
  
          public string NAME
          {
              get { return _name; }
              set { _name = value; }
          }
  
          public ICommand SaveCommand
          {
              get;
              set;
          }
  
          private bool CanExecuteSaveCommand()
          {
              return true;    // !string.IsNullOrEmpty(LastName);
          }
  
          private void CreateSaveCommand()
          {
              SaveCommand = new RelayCommand(SaveExecute, CanExecuteSaveCommand);
          }
  
          public void SaveExecute()
          {
              //Person.Save(_newPerson);
              NAME = "Changed Name";
          }
  
          public DashBoardViewModel()
          {
              //objModel.TestText = "This will change";
              NAME = "TestName";
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>