I have such a listbox like below:
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="385" Margin="21,138,0,0" VerticalAlignment="Top" Width="273" ItemsSource="{Binding Path=locationList}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Name="btnDelete" Click="btnDelete_Click" Width="15" Height="15" HorizontalAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Content="x" />
<CheckBox Name="checkBox" />
<TextBlock Name="textBox" Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And what I would like to do is to set checkbox for specific item this listbox.
I am trying to do it:
private void button4_Click(object sender, RoutedEventArgs e)
{
for(int i = 0; i < listBox.Items.Count; i++)
{
listBox.Items[i].checkBox = false;
}
}
I know I am doing an error. I would like to cast it to object of item and then set an item's property (this checkbox) to false. May anyone correct me ? Thank you in advance.
edit:
Before I was trying to do it this way:
foreach (var item in listBox.SelectedItems)
{
item.
}
but all possibilities I have got are just standard methods: Equals, GetHashCode, GetType, ToString... How I may refer to checkbox ?
Moreover I will supply my question with the insight. I would like to find a specific item by text which is in line in listbox (item) and then change checkbox for this item (same row in listbox). Second logic to be implemented is to set all rows to selected or unselected (this is what I am trying to do now).
Thank you for response.