我想显示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: 我不想要用户交互后的索引,它应该自动检索。