I have a ListBox with a fairly simple ItemTemplate containing a TextBlock and a Button . This appears as expected, but there is a problem. When I click on the contents of a ListBoxItem , that is, a text or a button, the row is not selected in the ListBox . If I click on the clean parts of the line, this will happen. I would like ListBoxItem be selected when I click anywhere in the row. What is needed to achieve this?
<ListBox ItemsSource="{Binding SomeElements}"> <ListBox.ItemTemplate> <DataTemplate> <ListBoxItem Selected="ListBoxItem_Selected"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Title}"></TextBlock> <Button>Click</Button> </StackPanel> </ListBoxItem> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
source share