wpf,How to show index of Collection in bind?
ListBox had been binded to a Collection o开发者_Python百科f string,I want to Button control to show index of element in collection.
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="{TemplateBinding Background}">
<Border BorderThickness="1">
<Button Height="20" Width="20" Content="{Binding ???}" Margin="2">
</Button>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Check these links.You may find what you are looking for
WPF: Binding lists in XAML- how can an item know its position in the list?
Numbered listbox
If you follow the approach described by 'Seven' in Numbered listbox the your code should look something like
<Button Height="20" Width="20" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplatedParent.(ItemsControl.AlternationIndex)}" Margin="2">
精彩评论