2

如何为将添加到列表框中的每个项目绑定复选框内容值?

<ListBox BorderThickness="2" Height="389" 
 HorizontalAlignment="Left" Margin="10,10,0,0" 
 Name="lboIssues" VerticalAlignment="Top" Width="175"
 SelectionMode="Multiple" ItemsSource="{Binding Mode=OneWay}">

然后这是我的 ItemTemplate

<ListBox.ItemTemplate>
  <DataTemplate>
   <StackPanel Margin="0,5,0,5" Orientation="Horizontal" >
    <CheckBox   Name="checkbox"
                Content="{Binding Path=Value, Mode=OneWay}"
                VerticalContentAlignment="Center"
        Margin="0,0,5,0"
                Width="Auto"
                IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, 
                AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
                IsTabStop="False" Checked="FilterCheckbox_CheckChanged" 
                Unchecked="FilterCheckbox_CheckChanged"/>
   </StackPanel>                         
  </DataTemplate>
</ListBox.ItemTemplate>`

当我检查时,复选框的内容值是空白的。

4

1 回答 1

1

尝试将其更改为

    <CheckBox   Name="checkbox"
                Content="{Binding Path=Value, Mode=OneWay}"
                VerticalContentAlignment="Center"
                Margin="0,0,5,0"
                Width="Auto"
                IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, 
                    AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
                IsTabStop="False" Checked="FilterCheckbox_CheckChanged" 
                Unchecked="FilterCheckbox_CheckChanged"
                Content="{Binding}"/>
于 2013-01-14T07:10:25.100 回答