title: How can I handle multiple CheckBoxes in the MVVM pattern?
body: <p>Binding checkbox in WPF is common issue, but I am still not finding example code which is easy to follow for beginners. I have check box list in WPF to select favorite sports’ name. The number of checkboxes is static in my case. Can anyone show me how to implement ViewModel for this issue?</p>
  
  <p><strong>FavoriteSportsView.xaml:</strong></p>
  
  <pre><code>  &lt;StackPanel Height="50" HorizontalAlignment="Left" VerticalAlignment="Top" 
    Width="150"&gt;
  
    &lt;CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}"  
    Command="{Binding Path=SportsResponseCommand}" 
    CommandParameter="Football" 
    Content="Football" 
    Margin="5" /&gt;
  
    &lt;CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" 
    Command="{Binding Path=SportsResponseCommand}" 
    CommandParameter="Hockey" 
    Content="Hockey" 
    Margin="5" /&gt;
  
    &lt;CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" 
    Command="{Binding Path=SportsResponseCommand}" 
    CommandParameter="Golf" 
    Content="Golf" 
    Margin="5" /&gt;
    &lt;/StackPanel&gt;
  </code></pre>
  
  <h2>FavoriteSportsViewModel.cs</h2>
  
  <pre><code>  public class FavoriteSportsViewModel.cs {
  
      //Since I am using the same IsChecked in all check box options, I found all check 
      //boxes gets either checked or unchecked when I just check or uncheck one option.
      //How do i resolve this issue? I don't think i need seprate IsChecked for each 
      //check box option.
  
      private bool _isChecked;
      public bool IsChecked{
        get {
             return _isChecked;
         }
  
        set { if (value != _isChecked) 
               _isChecked = value;
              this.OnPropertyChanged("IsChecked");
         }
      }
  
  
      //How do i detect parameter in this method?
      private ICommand _sportsResponseCommand;
      public ICommand SportsResponseCommand
      {
          get
          {
              if (_sportsResponseCommand== null)
                  _sportsResponseCommand= new
                      RelayCommand(a =&gt; DoCollectSelectedGames(), p =&gt; true);
              return _sportsResponseCommand;
          }
          set
          {
              _sportsResponseCommand= value;
  
          }
  
      }
  
      private void DoCollectSelectedGames(){ 
        //Here i push all selected games in an array
      }
  
  
      public abstract class ViewModelBase : INotifyPropertyChanged
      {
         public event PropertyChangedEventHandler PropertyChanged;
         public void OnPropertyChanged(string propertyName)
         {
           if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
         }
      }
  
    }
  </code></pre>
  
  <p>I'm not sure how to do the following in above ViewModel:
  1. How do I implement single method to handle all my options?
  2. how do I detect each one of the checkboxes to see whether checked or not
  3. How do i utlize CommandParameter?
  4. How do i implement SportsResponseCommand correctly</p>