我有ListBox一个相当简单的ItemTemplate定义 - 包含 aTextBlock和 a Button。这显示如预期,但有一个问题。当我单击 的内容(ListBoxItem即文本或按钮)时,不会在ListBox. 如果我点击它的空白部分。ListBoxItem当我单击该行的任意位置时,我希望选择。实现这一目标需要什么?
<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>