title: How To Count Checked CheckBox Inside ItemsControl
body: <p>I create multiple checkbox using <code>ItemsControl</code> in my WPF. But I need to make a limit by 20 for checkbox that can be checked/ticked by user. How do I can check the checked checkbox? </p>
  
  <p>I tried to research this as much as I can, and even binding checkbox to multiple command, but none of it is working. Below is my code to get through the checkbox that were inside the <code>Itemscontrol</code>. after, <code>IsChecked</code>.</p>
  
  <pre><code>for (int i = 0; i &lt; ItemsControlUnitPerStrip.Items.Count; i++)
  {
      ContentPresenter container = (ContentPresenter)ItemsControlUnitPerStrip.ItemContainerGenerator.ContainerFromItem(ItemsControlUnitPerStrip.Items[i]);
      CheckBox checkBoxChecked = container.ContentTemplate.FindName("CheckBoxUnitPerStrip", container) as CheckBox;
      if (checkBoxChecked.IsChecked == true)
      {
          //iOPC.WriteTag(checkBoxChecked.Uid, checkBoxChecked.IsChecked);
      }
  }
  </code></pre>
  
  <p>My XAML code </p>
  
  <pre><code> &lt;GroupBox x:Name="GroupBoxSamplingModeStrip" Header="Unit Per Strip" Grid.Row="0" Grid.Column="1"&gt;
                  &lt;ScrollViewer VerticalScrollBarVisibility="Auto"&gt;
                      &lt;ItemsControl x:Name="ItemsControlUnitPerStrip"
                        VirtualizingPanel.IsVirtualizing="True"
                        VirtualizingPanel.VirtualizationMode="Recycling"&gt;
                          &lt;ItemsControl.ItemsPanel&gt;
                              &lt;ItemsPanelTemplate&gt;
                                  &lt;UniformGrid Rows="{Binding StripRowsCount}"
                                   Columns="{Binding StripColumnsCount}"/&gt;
                              &lt;/ItemsPanelTemplate&gt;
                          &lt;/ItemsControl.ItemsPanel&gt;
                          &lt;ItemsControl.ItemTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;CheckBox x:Name="CheckBoxUnitPerStrip"
                                   Uid="{Binding Tag}"&gt;
                                      &lt;CheckBox.ToolTip&gt;
                                          &lt;ToolTip x:Name="TootlTipUnitPerStrip"&gt;
                                              &lt;TextBlock Text="{Binding Key}"/&gt;
                                          &lt;/ToolTip&gt;
                                      &lt;/CheckBox.ToolTip&gt;
                                  &lt;/CheckBox&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/ItemsControl.ItemTemplate&gt;
                      &lt;/ItemsControl&gt;
                  &lt;/ScrollViewer&gt;
              &lt;/GroupBox&gt;
  </code></pre>
  
  <p>Here the function code on how I generate the checkbox </p>
  
  <pre><code>  private void initializeUnitPerStrip()
      {
          unitPerStrip = new List&lt;UtilitiesModel&gt;();
          int totalRow = samplingModeModel.StripRows = 7;
          int totalCol = samplingModeModel.StripColumn = 15;
          int frontOffset = 8;
          int behindOffset = 0;
          for (int c = 1; c &lt; totalCol; c++)
          {
              for (int r = 1; r &lt; totalRow; r++)
              {
                  unitPerStrip.Add(new UtilitiesModel
                  {
                      Key = $"[{c}, {r}]",
                      Tag = $"{UTAC_Tags.S7Connection}DB{406},X{frontOffset}.{behindOffset}"
                  });
              }
          }
          ItemsControlUnitPerStrip.ItemsSource = unitPerStrip;
      }
  </code></pre>