如何为每个将添加到我的列表框中的项目绑定复选框内容值?
<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>`
我检查时,复选框的内容值为空。
答案 0 :(得分: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}"/>