Every time the itemsource property for my xamdatatree gets new data I would like to default the first node to IsChecked = true. I can do it like this when then tree first loads:
ItemsSource="{Binding OutageTypes, Mode=TwoWay}" DisplayMemberPath="OutageTypeDesc" NodeCheckedChanged="OutageTypeTree_OnNodeCheckedChanged" Loaded="OutageTypeTree_OnLoaded">
private void OutageTypeTree_OnLoaded(object sender, RoutedEventArgs e) { OutageTypeTree.Nodes[0].IsChecked = true; }
But I can't seem to find an event that fires after I change the dataset in OutageTypes to something else based on a selection the user makes in the UI. In the new dataset in object OutageTypes I have a property called IsChecked but defaulting it to true does not affect the tree.
How can I accomplish this?
Hello KrisVice,
Thank you for your post.
I have been investigating into this requirement that you are looking to achieve, and toward the end of your description, you mentioned an IsChecked property, which I imagine is either on your ViewModel or is on each of your data items that you are placing in your OutageTypes collection that you are binding to the tree. I would recommend that you continue with the latter of that statement. In other words, I would recommend that you add a property to your data item that you are displaying in the tree named IsChecked.
The reason I recommend this, is because the XamDataTree has a property named CheckboxMemberPath. If you create an IsChecked property on your data item and then set this CheckboxMemberPath to "IsChecked," it will check the nodes that represent data items that have this property set to true. Then, you only need manipulate your collection to keep the first item in your collection's IsChecked property true when you repopulate that particular collection.
I have attached a sample project which demonstrates this approach. In the sample, the data source is cleared and updated every 3 seconds and the item at collection[0] has its IsChecked property set to true.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thanks for the reply. What's the difference between this:
<ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout CheckBoxMemberPath="IsChecked"/> </ig:XamDataTree.GlobalNodeLayouts>
and this:
<XamDataTree CheckBoxMemberPath="IsChecked" />
If you only had a single NodeLayout in your XamDataTree, there is no difference in those two statements.
By placing it on the XamDataTree, it will map each node's IsChecked property to your chosen path, regardless of the NodeLayout that they sit in. By placing it on the NodeLayout, it will only map the IsChecked property on the nodes that exist in that particular layout.
Please let me know if you have any other questions or concerns on this matter.