title: WPF: Alternating colors on a ItemsControl?
body: <p>How do I get alternating colors on a ItemsControl? I have AlternationCount set to 2, but the ItemsControl.AlternationIndex property always returns 0.</p>
  
  <pre><code>        &lt;ItemsControl ItemsSource="{Binding}" AlternationCount="2"&gt;
              &lt;ItemsControl.Resources&gt;
                  &lt;Style x:Key="FooBar" TargetType="Grid"&gt;
                      &lt;Style.Triggers&gt;
                          &lt;Trigger Property="ItemsControl.AlternationIndex" Value="0"&gt;
                              &lt;Setter Property="Background" Value="Blue"/&gt;
                          &lt;/Trigger&gt;
                          &lt;Trigger Property="ItemsControl.AlternationIndex" Value="1"&gt;
                              &lt;Setter Property="Background" Value="Red"/&gt;
                          &lt;/Trigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/ItemsControl.Resources&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Grid Margin="0,0,0,10" Style="{StaticResource FooBar}"&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="25" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="100" /&gt;
                              &lt;ColumnDefinition Width="*" /&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Grid.RowDefinitions &gt;
                              &lt;RowDefinition Height="Auto" /&gt;
                              &lt;!--&lt;RowDefinition Height="Auto" /&gt;--&gt;
                          &lt;/Grid.RowDefinitions&gt;
  
                          &lt;CheckBox IsChecked="{Binding Checked, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" /&gt;
                          &lt;Label Grid.Column="1" Content="{Binding CompanyName}" /&gt;
                          &lt;Label Grid.Column="2" Content="{Binding TradeKey}" /&gt;
                          &lt;Label Grid.Column="3" Content="{Binding TradeDate}" ContentStringFormat="d" /&gt;
                          &lt;Label Grid.Column="4" Content="{Binding Cusip}" /&gt;
                          &lt;Label Grid.Column="5" Content="{Binding IssueName}" /&gt;
                          &lt;Label Grid.Column="6" Content="{Binding TotalUnits}" ContentStringFormat="N0" /&gt;
  
                          &lt;!--&lt;Expander Grid.Row="0" Grid.Column="7" Grid.ColumnSpan="7" IsExpanded="True"&gt;
                              &lt;Expander.Header&gt;
                                  &lt;StackPanel Orientation="Horizontal"&gt;
                                      &lt;Label Content="Allocations"/&gt;
                                      &lt;Button Content="Edit" Name="cmdEdit" Click="cmdEdit_Click"  /&gt;
                                  &lt;/StackPanel&gt;
                              &lt;/Expander.Header&gt;--&gt;
                          &lt;DataGrid Grid.Column="7" IsReadOnly="True" ItemsSource="{Binding Territories}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"&gt;
                              &lt;DataGrid.Columns&gt;
                                  &lt;DataGridTextColumn Header="Rep on Ticket" Binding="{Binding TradeCustomer.RepNameNotes}" /&gt;
                                  &lt;DataGridTextColumn Header="Rep # on Ticket" Binding="{Binding TradeCustomer.RepNumberNotes}" /&gt;
                                  &lt;DataGridTextColumn Header="State" Binding="{Binding TradeCustomer.AccountStateKey}" /&gt;
                                  &lt;DataGridTextColumn Header="Qty. on Ticket" Binding="{Binding TradeCustomer.Quantity, StringFormat=N0}" /&gt;
  
                                  &lt;DataGridTextColumn Header="Zip Code" Binding="{Binding ZipCode}" /&gt;
                                  &lt;DataGridTextColumn Header="State" Binding="{Binding State}" /&gt;
                                  &lt;DataGridTextColumn Header="Territory" Binding="{Binding Territory}" /&gt;
  
                              &lt;/DataGrid.Columns&gt;
  
                          &lt;/DataGrid&gt;
                          &lt;!--&lt;/Expander&gt;--&gt;
  
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;VirtualizingStackPanel /&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
              &lt;ItemsControl.Template&gt;
                  &lt;ControlTemplate&gt;
                      &lt;Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True"&gt;
                          &lt;ScrollViewer Padding="{TemplateBinding Control.Padding}" Focusable="False"&gt;
                              &lt;ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /&gt;
                          &lt;/ScrollViewer&gt;
                      &lt;/Border&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/ItemsControl.Template&gt;
          &lt;/ItemsControl&gt;
  </code></pre>