I have defined an ItemsControl in XAML as:
<ItemsControl ItemsSource="{Binding MyCollection}"
AlternationCount="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}">
<ItemsControl.Resources>
<DataTemplate x:Key="TemplateOne">
<Button Content="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Style="{StaticResource StyleOne}"/>
</DataTemplate>
<DataTemplate x:Key="TemplateTwo">
<Button Content="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Style="{StaticResource StyleTwo}"/>
</DataTemplate>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="ContentTemplate" Value="{StaticResource TemplateOne}"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="ContentTemplate" Value="{StaticResource TemplateTwo}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
The idea being that I can set different templates based on the current alternation index of the ItemsControl. Whilst this works and gives me the different data templates, I also want the content of the Button to show its alternation index, i.e., the index of the item in MyCollection. Any ideas where I may be going wrong?