Reputation: 464
I have a list that I bind to an itemsControl. The first items bind well be not the isChecked part.
Here is the code
var LstTemplates = Templates.Select(x=>new {TName=x.TemplateName,TId = x.Id, IsLinked = IsLinked(x.Id)});
itemsControlTemplates.ItemsSource = LstTemplates;
IsLinked is a function that returns a boolean
private bool IsLinked(int Id)
{
return (AnotherList.Any(x=>x.id==Id));
}
In the XAML
<CheckBox CommandParameter="{Binding TId}" Content="{Binding TName}" IsChecked="{Binding IsLinked}" />
The above does not work... or rather, the app freezes and breaks on a totally unrelated code.
But if I take the same "{Binding IsLinked}" and output it to a messagebox or even to the content of checkbox, then it shows...
Where did I go wrong?
Update: Okay, ignore the part where I said the code breaks at an unrelated code, that does misleading.
<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>
When I output 'IsLinked' to the content, it displays. How do I get it to bind to 'IsChecked'?
Upvotes: 0
Views: 233
Reputation: 3195
IsChecked is trying to do a TwoWay binding... I don't think this is possible on an anonymous type.
Try
IsChecked="{Binding IsLinked, Mode=OneWay}"
Upvotes: 2