【发布时间】:2015-06-14 09:51:56
【问题描述】:
我有一个带有 ItemTemplate 的 ListBox。 在 ItemTemplate 中,我有一个 Button 和一个 TextBlock。
<Window x:Class="ListBoxItemWithToggleButton.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox ItemsSource="{Binding ListItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Width="16" Height="16" Content="C" Padding="0" Margin="0,0,5,0"></Button>
<TextBlock Text="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
如果我点击 TextBlock 上的 ListBoxItem,ListItem 也会被选中, 但是如果我点击 Button 则不会选择 ListBoxItem。
如何在每次单击按钮时同时选择 Buttonclick 和 ListBoxItem?
【问题讨论】: