我正在使用WPF并且有一个列表框绑定到在运行时填充的数据表。列表框使用数据表并创建复选框。我希望能够通过选中和取消选中这些复选框来过滤数据网格。我的绊脚石试图设置并获取所选项目的值。您可以在下面看到我将列表框的selectedvalue路径绑定到列表框绑定的数据表的“id”列,但这样做只会返回所选复选框之一的值。
在后面的代码中,我可以遍历选定项目,但我不知道如何通过这条路线获取'id'列。
列表框的XAML:
<ListBox Name="lbMatchTypeFilter" ItemsSource="{Binding Path=relationshipTypesTable.dataTable.DefaultView}" SelectionMode="Multiple" SelectedValuePath="{Binding id}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="center" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" ToolTip="{Binding typeDesc}" Margin="0,0,5,0">
<TextBlock Text="{Binding displayString}" Background="{Binding color}" Margin="-4,0,0,0"/>
</CheckBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>