title: WPF MVVM Button Control Binding in DataTemplate
body: <p>I've seen other questions that deal with this, but never any explicit code describing the fix. I can't get a button inside of my ItemTemplate to bind to ANY command anywhere. Very frustrating. I am a complete MVVM newbie, btw.</p>
  
  <p>Here's my Window XAML.</p>
  
  <pre><code>&lt;Window x:Class="RET.CMS.Printing.App.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:RET.CMS.Printing.App.ViewModel"
      Height="350" Width="525"
      WindowStartupLocation="CenterScreen"
      Title="{Binding Path=DisplayName}"
      &gt;
  &lt;Window.Resources&gt;
      &lt;ResourceDictionary Source="MainWindowResources.xaml" /&gt;
  &lt;/Window.Resources&gt;
  &lt;Window.DataContext&gt;
      &lt;local:MainWindowViewModel /&gt;
  &lt;/Window.DataContext&gt;
  
  &lt;DockPanel Margin="10"&gt;
      &lt;Grid Margin="10" DockPanel.Dock="Top"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="1*" /&gt;
              &lt;ColumnDefinition Width="1*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Image Grid.Column="0" MaxHeight="75" MinHeight="25" HorizontalAlignment="Left"
                     Source="/RET.CMS.Printing.App;component/Resources/BarkleyREI%20%283%29.png" /&gt;
          &lt;TextBlock Grid.Column="1" HorizontalAlignment="Right" 
                      Height="30" VerticalAlignment="Top"
                      Style="{StaticResource TBHyperlinkStyle}"
                      &gt;
              Help
          &lt;/TextBlock&gt;
      &lt;/Grid&gt;
  
      &lt;Border Padding="10" DockPanel.Dock="Left"&gt;
          &lt;DockPanel&gt;
              &lt;Label Style="{StaticResource H1Style}" DockPanel.Dock="Top"&gt;YOUR PRINTERS&lt;/Label&gt;
              &lt;StackPanel Margin="10" DockPanel.Dock="Top"&gt;
                  &lt;Button Style="{StaticResource RegularButton}" HorizontalAlignment="Left" Command="{Binding RefreshPrintersCommand}"&gt;Refresh List&lt;/Button&gt;
              &lt;/StackPanel&gt;
                  &lt;ListBox ItemsSource="{Binding Printers}" DockPanel.Dock="Left"&gt;
                  &lt;ListBox.ItemContainerStyle&gt;
                      &lt;Style TargetType="ListBoxItem"&gt;
                          &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt;
                      &lt;/Style&gt;
                  &lt;/ListBox.ItemContainerStyle&gt;
                      &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                          &lt;Border Padding="5"&gt;
                              &lt;StackPanel&gt;
                              &lt;Grid&gt;
                                  &lt;Grid.ColumnDefinitions&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="75" /&gt;
                                  &lt;/Grid.ColumnDefinitions&gt;
                                  &lt;Grid&gt;
                                      &lt;Grid.RowDefinitions&gt;
                                          &lt;RowDefinition Height="*" /&gt;
                                          &lt;RowDefinition Height="*" /&gt;
                                      &lt;/Grid.RowDefinitions&gt;
                                      &lt;Grid Grid.Row="0"&gt;
                                          &lt;Grid.ColumnDefinitions&gt;
                                              &lt;ColumnDefinition Width="*" /&gt;
                                              &lt;ColumnDefinition Width="*" /&gt;
                                              &lt;ColumnDefinition Width="50" /&gt;
                                          &lt;/Grid.ColumnDefinitions&gt;
                                              &lt;TextBlock Style="{StaticResource TBHyperlinkStyle}" Text="{Binding Printer.Name}" Grid.Column="0" Margin="2" /&gt;
                                              &lt;TextBlock Text="{Binding Printer.Status}" Grid.Column="1" Margin="2"/&gt;
                                          &lt;Image Grid.Column="2" Margin="2"  /&gt;
                                      &lt;/Grid&gt;
                                      &lt;TextBlock Text="{Binding Printer.Debug}" Grid.Row="1"/&gt;
                                  &lt;/Grid&gt;
                              &lt;Button Grid.Column="1" Content="Pause"
                                      Command="{Binding Path=PausePrinterCommand}"
                                      &gt;&lt;/Button&gt;
                          &lt;/Grid&gt;
  
                          &lt;/StackPanel&gt;
                          &lt;/Border&gt;
                      &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
          &lt;/DockPanel&gt;
      &lt;/Border&gt;
  
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here's my ViewModel for it:</p>
  
  <pre><code> public class MainWindowViewModel:ViewModelBase
  {
      #region Fields
      private ObservableCollection&lt;PrinterViewModel&gt; _Printers = new ObservableCollection&lt;PrinterViewModel&gt;();
      #endregion Fields
  
      #region Properties
      public ObservableCollection&lt;PrinterViewModel&gt; Printers
      {
          get
          {
              if(_Printers==null)
                  LoadPrinters();
              return _Printers;
          }
      }
      #endregion Properties
  
      #region Constructor
      public MainWindowViewModel()
      {
          base.DisplayName = Resources.MainWindowViewModel_DisplayName;
  
          //bind commands
          RefreshPrintersCommand = new RelayCommand(param =&gt;this.LoadPrinters());
          PausePrinterCommand = new RelayCommand( param =&gt; this.PausePrinter(param));
      }
      #endregion Constructor
      #region Private Members
  
      private void LoadPrinters()
      {
          PrintersRepository pr = new PrintersRepository(Config.SettingsLoader.GetPrintServers());
          _Printers.Clear();
          pr.GetPrinters().ForEach(i =&gt;
              _Printers.Add(new PrinterViewModel(i)));
          OnPropertyChanged("Printers");
      }
      private void PausePrinter(object printerFullName)
      {
          var p = _Printers.Where(i =&gt; i.Printer.FullName == printerFullName as string);
      }
      #endregion Private Members
  
      #region Commands
      public ICommand RefreshPrintersCommand
      {
          get;
          private set;
      }
      public ICommand PausePrinterCommand
      {
          get;
          private set;
      }
  
      #endregion Commands
  }
  </code></pre>
  
  <p>Here's my PrinterViewModel:</p>
  
  <pre><code> public class PrinterViewModel:ViewModelBase
  {
      private Printer _Printer;
  
      private RelayCommand _PauseCommand;
      public PrinterViewModel(Printer p)
      {
          _Printer = p;
  
      }
      public Printer Printer { get { return _Printer; } }
  
      public RelayCommand PauseCommand
      {
          get
          {
              if (_PauseCommand == null)
                  _PauseCommand = new RelayCommand(param=&gt;_Printer.Pause());
              return _PauseCommand;
          }
      }
  
  }
  </code></pre>
  
  <p>Please help! Why can't i get this?</p>