Hello, I have a XamDataTree defined as follows:
<ig:XamDataTree x:Name="_MenuTree" ItemsSource="{Binding Menus}" SelectedDataItems="{Binding SelectedMenuItems}" NodeLineVisibility="Visible" IsExpandedMemberPath="IsExpanded" NodeCheckedChanged="TreeNodeCheckedChanged"> <ig:XamDataTree.CheckBoxSettings> <ig:CheckBoxSettings CheckBoxVisibility="Visible" CheckBoxMode="Auto" /> </ig:XamDataTree.CheckBoxSettings> <ig:XamDataTree.SelectionSettings> <ig:TreeSelectionSettings NodeSelection="Multiple" /> </ig:XamDataTree.SelectionSettings> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="MenuLayout" TargetTypeName="clsMenuItem" DisplayMemberPath="Description" CheckBoxMemberPath="IsSelected"> </ig:NodeLayout> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
The Menus property is in the ViewModel and is an ObservableCollection of clsMenuItem. clsMenuItem has the following properties: ID (int), Description (string) and ChildItems (ObservableCollection(of clsMenuItem))
I looked at one of the other similar posts on the forums board, but in my case, I don't see anything on the screen when then form loads, even though the Menus property has proper stuff in it.
What am I missing / doing wrong?
Hello Manasi,
When binding to the SelectedDataItems collection the underlying type should be an array of objects (public object[] SelectedMenuItems { get; set; }).
I am attaching a modified sample which illustrates this and also demonstrates the two methods I spoke of previously to either re-template the check box or change the display of the node to show the image. Currently, I have the setter for the CheckBoxStyle commented out so that you can see the modified node look. Simply uncomment the setter for the CheckBoxStlye to run the example with re-templating of the checkbox.
Please let me know if you have any questions.
Sincerely,
Valerie
Software Developer
Infragistics Inc
Valerie,
I made the nullable(boolean) changes as you said and it works OK now. The right nodes show the "-" sign.
I am not sure I follow on the second one. But I will try the method you suggested and get back.
Question: I just added another DataTree that only shows the nodes selected in the first tree. I set it as follows:
<ig:XamDataTree x:Name="_MenuTreeSelected" ItemsSource="{Binding SelectedMenuItems}" NodeLineVisibility="Visible" Grid.Column="1" Grid.Row="0"> <ig:XamDataTree.CheckBoxSettings> <ig:CheckBoxSettings CheckBoxVisibility="Hidden"/> </ig:XamDataTree.CheckBoxSettings> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="MenuLayoutSelected" TargetTypeName="entMenuItem" DisplayMemberPath="Description" CheckBoxMemberPath="IsSelected"> </ig:NodeLayout> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
I have set the ItemsSource to "SelectedMenuItems" which is the SelectedDataItems Property of the first big grid. "SelectedMenuItems" is IEnumerable(of Object) in the ViewModel class. SelectedMenuItems is always nothing, no matter what I do on the form in the first tree.
How can I connect the two?
Thanks for the help,
Manasi
The initial state of the checkbox is being determined by the underlying value that it is bound to. If you use a nullable bool and set the initial value (true = all checked, false = non checked, null = some checked) to indicate the value of the checked children then the tree will appear correctly initially.
For you second question, if you are looking to change the appearance of the Checkbox you can create your own style which re-templates the check box control and then tell the tree to use this style by creating a style targeting the XamDataTreeNodeControl and within this style set the CheckBoxStyle property to use your new checkbox style.
Otherwise if you want to add an additional image to the contents of the Node you can set the ContentTemplate property in a style targeting the XamDataTreeNodeControl and then add your own custom DataTemplate to display the node values along with the image. In order to display certain images based on whether the node is checked, you can use a relative source binding to the XamDataTreeNodeControl and set the visibility based on whether the node is checked. The XamDataTreeNodeControl’s datacontext is set to an instance of a XamDataTreeNodeContext which contains a ‘Data’ property to access the underlying data object and a ‘Node’ property to access properties of the node. You can either bind to the property in your object which is bound to the checkbox or to the node’s IsChecked property, For example:
Visibility="{Binding DataContext.Data.IsSelected,RelativeSource={RelativeSource AncestorType={x:Type ig:XamDataTreeNodeControl}},Converter={StaticResource VisConverter}}"/>
Or
Visibility="{Binding DataContext.Node.IsChecked,RelativeSource={RelativeSource AncestorType={x:Type ig:XamDataTreeNodeControl}},Converter={StaticResource VisConverter}}
Please let me know if you have any questions,
hi Valerie, apparently the ItemSource was being filled after the controls were loaded. I just assigned the "Menus" property in Form Loaded event and it worked fine. Now I have another question:
1) When the form loads, if there are only some child nodes checked and others unchecked, the parent node does not show the "-" (partially selected). But if I check / uncheck on the form, then the sign shows up. Is there something I have to do in the code-behind to show the right states of all check-boxes when the form loads?
2) Can I show Green Check and Red Cross images when the user checks / unchecks something on the form? How can I assign image property to a node depending on whether it is checked or unchecked?
Thanks,
PS: I tried to add an image here, didn't show up??
Your code appears to be correct, unless there is some sort of issue with data context not being propagated down to the tree, I don’t see any issue with this. I created a sample using the description of your data and your XAML and the tree appeared as expected. Please review the sample and see if you notice may differences which may attribute to your issue.
Let me know if you have any questions.
Sincerely