Xaml 如何在itemscontrol中获取项的索引

Xaml 如何在itemscontrol中获取项的索引,xaml,silverlight-4.0,itemscontrol,Xaml,Silverlight 4.0,Itemscontrol,我想在itemscontrol中显示项的当前索引: <TextBlock Foreground="#ffffffff" Margin="8,8,2,2" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Items.CurrentIndex}" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Righ

我想在itemscontrol中显示项的当前索引:

<TextBlock Foreground="#ffffffff"  Margin="8,8,2,2" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Items.CurrentIndex}" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>

这是我最好的猜测。我遇到了许多可能的解决方案,但使用alternationcount(silverlight似乎不支持)或其他方法并没有给我带来结果

itemscontrol如下所示:

<ItemsControl Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Grid.Row="6" ItemsSource="{Binding Alternatives, Mode=TwoWay}" ></ItemsControl>

绑定到itemscontrol的列表是一个具有某些属性的简单对象

我非常喜欢在XAML中这样做,因为我们在很多页面上重用该对象

任何好的建议都很好


PS:我不想要用户交互后的索引,它应该自动检索。

如果您想要itemscontrol中的项目索引-如果有某种选择,这对我来说是有意义的。但是ItemsControl没有选择器,因此没有选择,因此没有选择更改事件。因此,如果您想要一些选择,请使用列表框

还有一件事

<ItemsControl ItemsSource="{Binding Alternatives, Mode=TwoWay}" ></ItemsControl>
您希望迭代的其他地方

 view.MoveCurrentToNext();

你应该处理好第一个和最后一个项目,以及那些东西。

这是一个类似的问题,可能会有帮助,尽管它使用了listbox@Marshal:获取索引不应该从交互中获取,我需要该索引,以便我可以枚举我在items控件中显示的项。您的命令丢失了。itemscontrol中应该发生什么?没有选择。是否希望您的item datatemplate显示所选内容?否,在itemscontrol中,我有一个datatemplate,它显示绑定到它的对象中的一些数据。一些额外的信息是列表中的数字。假设我有20个项目绑定到itemscontrol:我想显示每个项目的索引,并在文本块中显示它。
 view.MoveCurrentToNext();