tags:

views:

24

answers:

1

I have next code:

  <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>

I want to bind my checkbox in dataTemplate to the ListBoxItem IsSelected property. Any idea how can I do this? P.S. I have use Multiple Selesction mode

+1  A: 

Try the following

<CheckBox x:Name="ThemeCheckbox" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
rudigrobler
Thank you very much. It works!!
Polaris