How do we bind the xamWebTree checkbox to a bool field in the data source?
For example, assuming the xamWebTree is bounded to
to a Categories collection with nested Products data. How can we get the checkbox values for the corresponding categories and products? Is there a way to bind the checkbox to a bool property in Category and Product?
What we are trying to do is ?
When the checkbox is selected on UI, we want to perform certain action on server and client. So how can we read the checkbox?
Thanks,
Hi,
So, the best way to bind a CheckBox to a bool field in your data source, is to use the ItemTemplate or HierarchicalItemTemplate property of the xamWebTree and place a Checkbox inside of it.
<igTree:XamWebTree.HierarchicalItemTemplate> <ig:HierarchicalDataTemplate ItemsSource="{Binding Path=Products}"> <ig:HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding ProductName}" IsChecked="{Binding MyProductBoolProperty, Mode=TwoWay}"> </DataTemplate> </ig:HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding CategoryName}" IsChecked="{Binding MyCategoryBoolProperty, Mode=TwoWay}"> </DataTemplate> </ig:HierarchicalDataTemplate> </igTree:XamWebTree.HierarchicalItemTemplate>
Hope this helps,
-SteveZ
Hi Stephen,
Thanks very much for the reply. It provides a way to bind a CheckBox to a bool property in my data source. However, I would like to use the CheckBox that comes with the xamWebTree (where the CheckBoxVisibility attribute is set to Visible), instead of manually place a CheckBox on each tree node. Any help is greatly appreciated.
Any reply to this? It appears that the "auto" checkboxing feature and databinding do not work together. In my opinion, it is a pretty useless feature if you can't tell the template what property on the underlying object you want the autogenrated checkbox to bind to.
This issue has been fixed, and in the next SR for both 9.1 and 9.2 you will be able to bind to the IsChecked property of a XamWebTreeItem.
Hi SteveZ
Do you have an example of how to do this in xaml or code? I'm using a HierarchicalItemTemplate.
Thanks
Kevin
Have you received a response?
I actually got really weird behavior when I followed your example. It looked like one text box item was nested within another. The following worked for me ... Thanks for your help!
<igTree:XamWebTree x:Name="MyTree" CheckBoxVisibility="Visible" CheckBoxMode="Auto" ItemsSource="ParentData">
<igTree:XamWebTree.DefaultItemsContainer>
<DataTemplate>
<igTree:XamWebTreeItem IsChecked="{Binding MyParentProperty, Mode=TwoWay}"/>
</DataTemplate>
</igTree:XamWebTree.DefaultItemsContainer>
<igTree:XamWebTree.HierarchicalItemTemplate>
<ig:HierarchicalDataTemplate ItemsSource="{Binding ChildData}">
<TextBlock Text="{Binding ChildDescription}" />
<ig:HierarchicalDataTemplate.DefaultItemsContainer>
<igTree:XamWebTreeItem IsChecked="{Binding MyChildProperty, Mode=TwoWay}" />
</ig:HierarchicalDataTemplate.DefaultItemsContainer>
<ig:HierarchicalDataTemplate.ItemTemplate>
<TextBlock Text="{Binding ParentDescription}" />
</ig:HierarchicalDataTemplate.ItemTemplate>
</ig:HierarchicalDataTemplate>
</igTree:XamWebTree.HierarchicalItemTemplate>
</igTree:XamWebTree>
No, I spoke too soon. I saw it after applying SR2. It works like a charm.
Thanks!!!
Do you have the latest SR? As it was made a DP after the release.
http://es.infragistics.com/dotnet/netadvantage/silverlight/line-of-business.aspx#Downloads
And to use the property, all you need to do, is put an instance of a XamWebTreeItem in your ItemTemplate and set a binding on the IsChecked property.
<DataTemplate><ig:XamWebTreeItem IsChecked="{Binding MyProp, Mode=TwoWay}" ><TextBlock Text="{Binding DisplayProp}"/></ig:XamWebTreeItem></DataTemplate>
I don't see an IsCheckedProperty dependency property on XamWebTreeItem, so I'm assuming it wasn't fixed in 9.2 like Steve Z said.