Answer the question
In order to leave comments, you need to log in
How to access an item in an ItemsControl by its index in WPF C#?
You need to access the button in the ItemsControl by index. For example, I have 100 entries and I want to get an instance of the 5th button so that I can change it as I want. Source xaml:
<ItemsControl x:Name="mainList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="40" Margin="1 1 2 3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="Button" Tag="{Binding}" Click="Button_Click">
<Image Source="/Resources/button.png"></Image>
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Answer the question
In order to leave comments, you need to log in
ItemsControl
doesn't support selection, use ListBox there SelectedIndex
You can get by index in different ways.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question