我有下一个代码:
<ListBox Grid.Column="1" Grid.Row="4" Grid.RowSpan="2" Margin="0,0,1,0" MinHeight="80" Name="lbThemes" SelectionMode="Multiple" IsEnabled="True">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox x:Name="ThemeCheckbox" />
<TextBlock Text="{Binding Path=label, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想将dataTemplate中的复选框绑定到ListBox Item IsSelected属性。知道我该怎么办? 附:我使用多种选择模式
答案 0 :(得分:4)
尝试以下
<CheckBox x:Name="ThemeCheckbox" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />