0
我有一组本地高分(ObservableCollection),它们绑定到ListBox的数据,所以我可以显示它们。这是我现在有的,第一个TextBlock的“{绑定索引}”是我尝试抓取当前项目的索引的位置,但我不完全确定是否可以通过数据绑定:数据绑定列表框中的项目的索引?
<ListBox Grid.Row="1" x:Name="localScoresListBox" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Index}" Grid.Column="0" />
<TextBlock Text="{Binding PlayerName}" Grid.Column="1" />
<TextBlock Text="{Binding Score}" Grid.Column="2" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
所以我的问题。使用数据绑定,你可以获取当前项目的索引吗?
如果有可能,我相信它会是基于0的,因为我希望第一个排名是1而不是0,你可以做一些类似{绑定索引+1}的事情吗?
编辑:这里有一个类似的问题WPF和似乎没有成为一个办法做到这一点,那么:WPF ListBox bind to index of the item