When you click on a control inside the ListBox
(its DataTemplate
), I want to know which item that is so that I can select that item.
I have a WPF application with a ListBox
. Using a DataTemplate
, I have a TextBlock
and a Textbox
inside it.
<ListBox PreviewMouseLeftButtonDown="myHandler">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock />
<TextBox />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Right now, if you click on the TextBlock, it selects the overall item. But if you click inside the TextBox (to repeat: Box, not Block), it doesn't select the item.
Is there code that I can put inside the ListBox's PreviewMouseLeftButtonDown that can tell me the index of the ListBoxItem whose TextBox I clicked? Or some other way to select the ListBoxItem?