Automatically number items in a wpf listbox
Posted
by evan
on Stack Overflow
See other posts from Stack Overflow
or by evan
Published on 2010-04-15T16:49:10Z
Indexed on
2010/04/15
16:53 UTC
Read the original article
Hit count: 265
I have a person class with two properties, Name an Age. I know how to use databinding to display a collection of person in a wpf list box and how to modify the listitemtemplate to customize how each person is displayed.
Now I'd like to number each person on the list according to the order they appear on the list (which could change as the the items were sorted via name or age in the display). Is there a way to do that with the item template so instead of having a list like
Rob - 14
John - 56
Suzy - 32
it would be
1) Rob - 14
2) John - 56
3) Suzy - 32
Basically i'd like to do something like:
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
**<TextBlock Text="{Binding CurrentPositionInList}" />**
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Age}" />
</WrapPanel>
</DataTemplate>
Thanks in advance!
© Stack Overflow or respective owner