title: How to use AlternationIndex in ItemsControls?
body: <p>I have seen some articles that show how to use <code>AlternationIndex</code> with <code>ListBox</code>es or <code>ListView</code>s, but I had spent a few hours trying to get alternating background colors on the base <code>ItemsControl</code> class and nothing seems to work. All <code>ListBox</code> samples I saw use <code>ListBoxItem</code> as the target type for the style that sets the background based on<code>AlternationIndex</code> - like this one from <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.alternationcount(v=vs.110).aspx" rel="noreferrer">MSDN</a>:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.Resources&gt;
          &lt;Style x:Key="alternatingWithTriggers" TargetType="{x:Type ListBoxItem}"&gt;
              &lt;Setter Property="Background" Value="Blue"/&gt;
              &lt;Setter Property="Foreground" Value="White"/&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="ListBox.AlternationIndex" Value="1"&gt;
                      &lt;Setter Property="Background" Value="CornflowerBlue"/&gt;
                      &lt;Setter Property="Foreground" Value="Black"/&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property="ListBox.AlternationIndex" Value="2"&gt;
                      &lt;Setter Property="Background" Value="LightBlue"/&gt;
                      &lt;Setter Property="Foreground" Value="Navy"/&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
  
      &lt;/Grid.Resources&gt;
      &lt;ListBox AlternationCount="3" ItemsSource="{StaticResource data}" 
               ItemContainerStyle="{StaticResource alternatingWithTriggers}"&gt;
      &lt;/ListBox&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I want to use the <code>ItemsControl</code> because I do not want the selection functionality and I think restyling a <code>ListBox</code> to hide it might not be the best choice.</p>
  
  <p>This is one of the things I was trying:</p>
  
  <pre><code>&lt;DataTemplate DataType="{x:Type vm:ObservableCollectionItem}"&gt;
      &lt;Grid&gt;
          &lt;!-- some content here --&gt;
      &lt;/Grid&gt;
  &lt;/DataTemplate&gt;
  
  &lt;!-- ... --&gt;
  
  &lt;ItemsControl
      ItemsSource="{Binding ObservableCollectionItems}"
      AlternationCount="2"
  &gt;
      &lt;ItemsControl.ItemContainerStyle&gt;
          &lt;Style&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="ItemsControl.AlternationIndex" Value="0"&gt;
                      &lt;Setter Property="Grid.Background" Value="Red"&gt;&lt;/Setter&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property="ItemsControl.AlternationIndex" Value="1"&gt;
                      &lt;Setter Property="Grid.Background" Value="Blue"&gt;&lt;/Setter&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/ItemsControl.ItemContainerStyle&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>The problem I saw was that the visual tree has a list of <code>ContentPresenter</code>s that have <code>ItemsControl.AlternationIndex</code> alternate between 0 and 1, but the <code>Grid</code> in each <code>ContentPresenter</code> has <code>ItemsControl.AlternationIndex</code> set to 0.</p>
  
  <p>There is probably something obvious I am missing...</p>