【发布时间】:2012-02-07 16:25:00
【问题描述】:
我想在 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 似乎不支持)或其他方法并没有给我结果。
items 控件如下所示:
<ItemsControl Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Grid.Row="6" ItemsSource="{Binding Alternatives, Mode=TwoWay}" ></ItemsControl>
绑定到 itemscontrol 的列表是一个带有一些属性的简单对象。
我真的很喜欢在 XAML 中执行此操作,因为我们在很多页面上重复使用该对象。
任何好的建议都会很棒。
PS:我不希望用户交互后的索引,它应该自动检索。
【问题讨论】:
-
stackoverflow.com/questions/4333807/… 这是一个类似的问题,虽然它使用列表框,但它可能会有所帮助
-
@Marshal : 获取索引不应该从交互中获取,我想要那个索引,这样我就可以枚举我在 itemscontrol 中显示的项目
标签: xaml silverlight-4.0 itemscontrol