【发布时间】:2009-04-23 18:36:43
【问题描述】:
我有一个 AvailableItems 列表,我想将其显示为复选框列表,以便用户可以选择要生成的项目,然后将其存储在另一个名为 ItemsToGenerate 的列表中(我的列表实际上只是列表字符串)。
用相应的复选框显示所有可用的项目很容易:
<ItemsControl ItemsSource="{Binding Path=AvailableItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
但现在我需要将每个 Checkbox.IsChecked 属性绑定到该项目位于 ItemsToGenerate 列表中的事实。我想过像这样制作ListContainmentToBoolConverter:
IsChecked="{Binding Path=ItemsToGenerate,
Converter={StaticResource ListContainmentToBoolConverter}}"
但这不起作用,因为我缺少ConverterParameter 来传递每个项目的值,但我不能这样做,因为ConverterParameter 不支持绑定。
有什么想法吗?
【问题讨论】: