title: Relay Commands Command Parameter
body: <p>I am trying to work with the MVVM principles within a small WPF project using C#.
  I have a <code>ListBox</code> that is populated with <code>CheckBox</code>es created through binding back to the ViewModel. I also have a command bound to the <code>CheckBox</code>es and wish to pass the <code>CheckBox</code>es <code>Content</code> as a <code>CommandParameter</code>. I was looking for something like this:</p>
  <pre><code>&lt;Binding ElementName=&quot;&quot; Path=&quot;Content&quot;/&gt;
  </code></pre>
  <p>Unfortunately, because the <code>CheckBox</code>es are created through a binding I don’t have the element name.</p>
  <p>The code for <code>ListBox</code> / <code>ListBoxItem</code> <code>Style</code> is this:</p>
  <pre><code>&lt;Style x:Key=&quot;CheckBoxListStyle&quot; TargetType=&quot;{x:Type ListBox}&quot;&gt;
      &lt;Setter Property=&quot;SelectionMode&quot; Value=&quot;Multiple&quot;&gt;&lt;/Setter&gt;
      &lt;Setter Property=&quot;ItemContainerStyle&quot;&gt;
          &lt;Setter.Value&gt;
              &lt;Style TargetType=&quot;{x:Type ListBoxItem}&quot; &gt;
                  &lt;Setter Property=&quot;Margin&quot; Value=&quot;2&quot; /&gt;
                  &lt;Setter Property=&quot;Template&quot;&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType=&quot;{x:Type ListBoxItem}&quot;&gt;
                              &lt;CheckBox Command=&quot;{Binding SelectedItemCommand, Mode=OneWay, Source={StaticResource comd}}&quot;&gt;
                                  &lt;CheckBox.CommandParameter&gt;
                                      &lt;MultiBinding Converter=&quot;{StaticResource cv}&quot;&gt;
                                          &lt;Binding ElementName=&quot;&quot; Path=&quot;Content&quot;/&gt;
                                      &lt;Binding ElementName=&quot;&quot; Path=&quot;IsChecked&quot;/&gt;
                                      &lt;/MultiBinding&gt;
                                  &lt;/CheckBox.CommandParameter&gt;
                                  &lt;ContentPresenter&gt;&lt;/ContentPresenter&gt;
                              &lt;/CheckBox&gt;
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Style&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  <p>And its implementation is:</p>
  <pre><code>&lt;ListBox Grid.Row=&quot;1&quot; Style=&quot;{StaticResource CheckBoxListStyle}&quot; Name=&quot;lstProducts&quot; ItemsSource=&quot;{Binding stampInfo, Mode=OneWay, Source={StaticResource vmStamp}}&quot; 
          DisplayMemberPath=&quot;Country&quot; &gt;
  &lt;/ListBox&gt;
  </code></pre>
  <p>Ultimately my goal is to be able to display the text <code>Content</code>s (Countries in this case) of all the selected items  in a text box were each country is separated by a comma. The only thing I am currently missing is the <code>Country</code>.</p>