【问题标题】:Bind CheckBox from DataTemplate to TemplatedParent in ListBox将 DataTemplate 中的 CheckBox 绑定到 ListBox 中的 TemplatedParent
【发布时间】:2010-10-06 08:46:08
【问题描述】:

我有下一个代码:

  <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 中的复选框绑定到 ListBoxItem IsSelected 属性。知道我该怎么做吗? 附言我使用了多选模式

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    试试下面的

    <CheckBox x:Name="ThemeCheckbox" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多