I have a ListView
containing only buttons. What I want to do is pretty simple, I want to have the index of the button that has been clicked. The count of the list varies from 0 to 100, so when the user clicks on button 6, I need this number for processing.
I defined my ListView
like this:
<ListView Name="myListView"
ItemsSource="{Binding Source={StaticResource myDataModel},
Path=StatusList,
Mode=OneWay}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Button Mode=OneWay}"
Click="Button_Click"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My original idea was to create a custom button with an ID and bind the index to the ID but I can't figure out how to do that.
I tried:
int a = myListView.Items.IndexOf(((Button)sender));
inside the event handler, but it always returns 0xffffffff can anybody tell me how to get the index of the clicked button?