In WPF: How can i pass the index of a ItemsSource loop as a CommandParameter?
<ItemsControl ItemsSource="{Binding PageList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Content="{Binding Name}"
Command="{Binding DataContext.ChangePageCommand, ElementName=Window}"
CommandParameter="INDEX OF ACTUAL ITEM AT ITEMSSOURCE GOES HERE" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
So, what i want is to pass the pushed button number to the Command method.
Thank you!
Simple way to do it.
First, screw indexes. They suck. Bind to
SelectedItem
Now, you don't have to try and pass the index into the parameter, because the selected page is already in your ViewModel.