我要顯示一個項目的當前指數在一個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="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:我不希望用戶交互後的索引,它應該自動檢索。
http://stackoverflow.com/questions/4333807/how-to-get-listbox-selected-index這是一個類似的問題,雖然它使用列表框 – Marshal 2012-02-08 08:02:40
@Marshal:獲取索引shouldn'從互動中獲得,我想索引,所以我可以枚舉項目控件 – Terry 2012-02-08 08:24:09