I am working with the sample provided in this thread: http://es.infragistics.com/community/forums/t/106614.aspx
But I got a problem: If I right click the same node twice, it shows the wrong menu item. For ex: If I right click Expand on a collapsed node, then it expands it. If I right click on it again, it shows Expands, instead of Collapse menu item. I have handled visibility in the class inside the sample project itself. But it is not working properly. please see attached image.
What is wrong with the code?
Thanks
I tried to paste code in my previous question, but there was some problem. So I am attached the project here.
Hi Mohni,
I’ve constructed and attached a sample specifically demonstrating the behavior that you are interested in.
Please let me know if you have any questions regarding this approach or if you have any further questions that I may assist you with.
Warm regards,
Chris
Hi Chris,
thanks for the suggestion. I will try it and let you know. Can you elaborate on what you mean by "then creating an item template specifically for that NodeLayout to include its own Checkbox."
Do you have a sample or link to do this?
EDIT: I added two layouts, with CheckBoxVisibility off like you said, but now I get extra levels like "CategoryLayout" and "OptionsLayout"? How to get rid of these? If there are no options in the list of products, then I get an empty "OptionsLayout" level, with nothing under it.
EDIT: I have attached a sample to demonstrate my object behavior. If you look at the sample, you will see that, clsSubItem is a property of clsItem. clsSubItem can be either A or B. The nodes that bind to clsItem.SubItemB should be independent.
thanks
Chris,
I changed my object structure a little, to work with two layouts. I have attached that project here. I am not sure that my functionality is possible with which sample project, but any pointers will help. In this scenario, I get empty nodes for each layout if the underlying property does not have any items in it.
Kindly let me know which object structure is best suited for my requirement. Basically, clsSubItemB type nodes should be independent of the rest of the tree. Should they be exposed as list property of clsItem or wrapped in clsItem inside list of clsItem? I am not sure yet, how they layout works stuff out.
Please take a look at the two samples and let me know which structure is the best suited. Also, I did not find an ItemTemplate for NodeLayout in the help files. Can you send me a link or modify one of my samples?
thanks.
Hi Chris, I created an ItemTemplate like you said and also specified CheckboxVisibility = Collapsed on the second NodeLayout. But it does not work.
Please check what is wrong. Also, When I check/uncheck the template checkbox, I go to the function specified, but how can I get the Node associated in that function?
Again, there was some problem pasting code. So I have attached the new project here. In this project, I still get the "ItemLayout" and "SubItemLayout" nodes. How to get rid of those? And even if I set CheckBoxVisibility to Collapsed on the second node layout, it shows up still.
Thanks,
can anyone please take a look and let me know? Thanks
The specific node selection behavior that you are interested is possible by maintaining a reference to the checked state for ChildNodes by adding an IsChecked property to your ChildNode and ParentNode classes, as well as adding a property off of the ChildNode class for keeping track of its associated parent; which is then set on the ChildNode object in your data.
Next, update the IsChecked property on your ParentNode, whenever a ChildNode’s checkbox is checked, (the checkbox within the ChildNode’s item template can be bound to the underlying IsChecked property to ensure it is updated) and the CheckBoxMemberPath will be set to the IsChecked property of ParentNode, (which itself is being set whenever a child node is checked, within your ParentNode class).
I have modified your earlier sample for achieving this behavior and attached it for further context, (as well as the XAML snippet, below).
<igDT:XamDataTree Name="OtherTree">
<igDT:XamDataTree.CheckBoxSettings>
<igDT:CheckBoxSettings CheckBoxVisibility="Visible"/>
</igDT:XamDataTree.CheckBoxSettings>
<igDT:XamDataTree.GlobalNodeLayouts>
<igDT:NodeLayout Key="ParentLayout"
TargetTypeName="ParentNode"
DisplayMemberPath="Name" CheckBoxMemberPath="IsChecked">
</igDT:NodeLayout>
<igDT:NodeLayout Key="ChildLayout"
TargetTypeName="ChildNode"
DisplayMemberPath="Name">
<igDT:NodeLayout.CheckBoxSettings>
<igDT:CheckBoxSettingsOverride CheckBoxVisibility="Collapsed">
</igDT:CheckBoxSettingsOverride>
</igDT:NodeLayout.CheckBoxSettings>
<igDT:NodeLayout.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Path=Node.Data.IsChecked}" />
<TextBlock />
</StackPanel>
</DataTemplate>
</igDT:NodeLayout.ItemTemplate>
</igDT:XamDataTree.GlobalNodeLayouts>
</igDT:XamDataTree>
There is one drawback to this implementation due to the use of nested collections within your ParentNode collection, as the XamDataTree will always display a node level for each sub-collection, using the associated NodeLayout key for the display name of that node level(s); there is currently no supported means of hiding these nodes and this secondary behavior will require a product idea.
Product ideas are used to gauge the interest for particular features that are not yet supported, (including new controls/products); product ideas which have the most number of votes become candidates for implementation and integration into Infragistics products for upcoming releases.
You may submit a product idea for this behavior by clicking the following link, (http://ideas.infragistics.com/forums/192363-wpf); you will be directed to the Infragistics product idea website, within the WPF product group. Simply enter a brief description of your idea into the suggestion box and select ‘Post a new idea…’, then within the Description dialog, provide as much detail as possible as it relates to your idea, (screenshots/mock-ups are encouraged), provide your email address in the appropriate dialog, if no yet signed in and then select the ‘Post idea’ button.
If you have any further questions that I may assist you with, please let me know.
Chris K.
Your certainly welcome! The XamDataTree doesn’t support user customizable conditional checkbox selection, (out of the box anyway) aside from what’s handled for you when it’s CheckBoxMode is set to ‘Auto’; this would make an interesting product idea.
Further, the XamDataTree’s NodeCheckChanged event doesn’t expose a cancelation argument, but it is possible to achieve both a conditional check behavior, (which you will need to handle, yourself) as well as a pseudo checked cancellation for nodes.
As an example, say you have several sibling nodes belonging to some parent node and you only want one of those nodes to be checked at any given time, (effectively wanting to cancel the checked state for any of its sibling nodes, should the condition arise that they might also enter a checked condition); you could hook into the NodeCheckedChanged event of the XamDataTree, check if your node in question is ‘potentially’ being changed to a checked state and if so, then iterate thru its sibling nodes to first verify that they are not also checked, if at least one is checked, then return false, otherwise return true and allow that node to become checked.
With the CheckboxMode set to ‘Auto’ on the XamDataTree, child nodes of the parent node which has had its checked event ‘cancelled’ will behave as if it’s parent was never checked at all; however, they themselves will remain checkable.
I’ve constructed and attached a sample that demonstrates this approach for further context and I’ve limited the scope of nodes to be checked to those of ‘Type.C’, from our previous sample as you might want some way of limiting this behavior to a particular set of nodes.
Please let me know if you have any further questions.
P.S. If you do have any new questions, please create a new thread for it, (as this one may become difficult for other IG community members to follow, as it encompasses several different issues) and include the link to that thread in your response here and I, (if I can) or one of my team mates will assist you on that new thread.
Thanks a lot Chris! that works!
I have another question. this is inside a normal XamDataTree with checkBox mode = auto.
When the TreeNodeCheckChanged fires, is it possible to cancel the event if a certain condition is not met? So if a node got checked (childNode) because another node is checked (parentNode), but I don't want this node (childNode) to be checked (maybe other child nodes can be checked or not), how can I cancel the changing of the node?
If I cancel, will it again fire the event for all the related nodes, if I have check box mode = auto?
The behavior of managing the CheckBox type for your templated Node checkboxes based on the presence of child nodes is possible by binding the IsThreeState property on your CheckBox template to a converter that will then return the value of the HasChildren property off of the associated node’s DataContext.
The XamDataTree does not have an event associated with clicking on or changing the checked state of its checkboxes; there is however, an IsChecked property exposed from XamDataTreeNode that may be used in conjunction with the INotifyPropertyChanged interface to monitor the checked state for nodes.
In this particular scenario, since the XamDataTree’s checkboxes aren’t used anyway, you could take advantage of the built-in WPF checkbox’s click event, (via the template Checkbox in NodeLayouts.ItemTemplate) for whatever behavior you had in mind.
As for styling the WPF checkboxes to match the style for those used by the XamDataTree, you will be able to reuse its default style, (which you’ve already defined in your sample as “cbstyle”) that can be set as the style for the template checkboxes within the NodeLayouts.ItemTemplate.
I’ve modified our earlier sample to include these changes as well as the following code snippet for further context.
<!--XAML for the XamDataTree--><igDT:XamDataTree Name="OtherTree"> <igDT:XamDataTree.Resources> <local:ThreeStateConverter x:Key="ThreeStateConverter"/> </igDT:XamDataTree.Resources> <igDT:XamDataTree.GlobalNodeLayouts> <igDT:NodeLayout Key="NodeLayout" TargetTypeName="Node" DisplayMemberPath="Name"> <igDT:NodeLayout.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" IsChecked="{Binding Path=Node.Data.IsChecked}" IsThreeState="{ Binding Converter= {StaticResource ThreeStateConverter}}"/> Style="{StaticResource cbstyle}" <TextBlock Text="{Binding Path=Node.Data.Name}" Margin="5, 0, 0, 0"/> </StackPanel> </DataTemplate> </igDT:NodeLayout.ItemTemplate> </igDT:NodeLayout> </igDT:XamDataTree.GlobalNodeLayouts></igDT:XamDataTree>
//Value Converterpublic class ThreeStateConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { XamDataTreeNodeDataContext nodeContext = value as XamDataTreeNodeDataContext;
return nodeContext.Node.HasChildren; }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return new NotImplementedException(); }}
I tried it like this and it works to an extent. I found only one problem: If I click repeatedly on the checkbox of a child node, it turns into "True", then "Indeterminate" and then "False". Is there a way to handle the indeterminate state if the node does not have any children? So if some parent node has 3 children, but only 1 is checked, then I understand it can show "Indeterminate" state, but how to handle to child node?
What I mean, can I have three state checkbox for parent nodes, but two states for the lowest level child nodes?
Also, is there a checkbox click event on XamDataTree? Is it possible to make the DataTemplate checkbox look like XamDataTree checkbox? What style I can use for this?
You are certainly welcome! As this implementation uses the built-in WPF Checkbox, you will need to use its IsThreeState property, setting it to ‘True’.
The best place to enable this behavior, in this case is within your ItemTemplate, where you’ve defined your NodeLayouts, as in the following code snippet.
<igDT:NodeLayout.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox IsThreeState="True" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" IsChecked="{Binding Path=Node.Data.IsChecked}"/> <TextBlock Text="{Binding Path=Node.Data.Name}" Margin="5, 0, 0, 0"/> </StackPanel> </DataTemplate></igDT:NodeLayout.ItemTemplate>
Next, you will need to set the type for your IsChecked property off of the Node class to a nullable type, such as ‘bool?’; this will allow you to manage an intermediate state for your checkboxes, by getting/setting that checkboxes IsChecked property to null.
Bear in mind, however that since you need to manual define the behavior used for checkbox interactions between nodes for your requirement, that this behavior too will need to be accounted for in your approach.
Please let me know if you have any further questions that I may assist you with.
Warm regards,Chris K.