【发布时间】:2012-12-19 23:38:08
【问题描述】:
我有一个绑定到 itemsControl 的列表。第一项绑定得很好,不是 isChecked 部分。
这里是代码
var LstTemplates = Templates.Select(x=>new {TName=x.TemplateName,TId = x.Id, IsLinked = IsLinked(x.Id)});
itemsControlTemplates.ItemsSource = LstTemplates;
IsLinked 是一个返回布尔值的函数
private bool IsLinked(int Id)
{
return (AnotherList.Any(x=>x.id==Id));
}
在 XAML 中
<CheckBox CommandParameter="{Binding TId}" Content="{Binding TName}" IsChecked="{Binding IsLinked}" />
上述方法不起作用......或者更确切地说,应用程序在完全不相关的代码上冻结并中断。
但如果我采用相同的“{Binding IsLinked}”并将其输出到消息框甚至复选框的内容,那么它会显示...
我哪里做错了?
更新: 好的,忽略我所说的代码在不相关的代码处中断的部分,这会产生误导。
<ItemsControl Name="itemsControlTemplates" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="2">
<CheckBox CommandParameter="{Binding TId}" Content="{Binding TName}" IsChecked="{Binding IsLinked}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
当我将“IsLinked”输出到内容时,它会显示。如何让它绑定到“IsChecked”?
【问题讨论】:
-
or rather, the app freezes and breaks on a totally unrelated code这里没有足够的信息来回答。这就是编写一个原型的地方,它完全可以做到,而且只有这才有帮助。
标签: c# wpf wpf-controls checkbox