0
我试图使用CheckBoxes达到List列表,但是在XAML中有一些与Dictionary的值绑定的值到IsChecked
属性的问题。词典<object,bool>作为带有复选框的列表
我的列表模板:
XAML
<ItemsControl Name="lb" ItemsSource="{Binding Movies}" BorderThickness="0">
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Style>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<CheckBox Content="{Binding Key.MovieId}" IsChecked="{Binding Converter={StaticResource DictConvert}, ConverterParameter=Key}" Command="{Binding DummyCommand}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
转换
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
KeyValuePair<Movie, bool> bla = (KeyValuePair<Movie, bool>)value;
var dict = value as Dictionary<Movie, bool>;
List<KeyValuePair<Movie,bool>> list = new List<KeyValuePair<Movie, bool>>();
list.Add(bla);
dict = list.ToDictionary(k => k.Key, k => k.Value);
if (dict != null)
{
return true;
}
throw new NotImplementedException();
}
调试器到达这个 “返回true” 行,所以它应该工作,但我越来越XamlParseException
。任何人都可以帮助我?,我试图创建ObservableDictionary,但放弃了 - 这是唯一的方法?
请问您能为此发布示例代码吗?当我做多值转换器时,我遇到了convertback方法的问题。 – Gratz 2013-04-12 07:02:29