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,
Thank you for the sample. But I see you are not using a visibility converter. Is it possible to make it work with the visibility converter?
I tried to use your way in my project, with the help of ContextMenu_Opening function. Problem is, I cannot access the Menuitems in the contextmenu by name, I have to hard-code the index to set visibility of all four items. Like 0 = Expand, 1 = Collapse, etc.
I also cannot use ig:XamContextMenu, it has to be normal ContextMenu like the sample project I attached. So if I have contextmenu on XamDataTree, it has to always be XamContextMenu?
I have another question, since your sample demonstrated what I am doing anyway: I have the following kind of structure:
clsCategory { categoryID, categoryName, description, Products }
clsProduct { productID, productName, categoryID, quantityPerUnit, ProductOptions }
clsProductOption { productID, productoptionID, optionName }
Is it possible to have checkboxmode = Auto for Category and Product but not for Productoption? So, user can have a Product selected, without any Option. But if Product is selected, Category should get updated.
UPDATE: With Checkbox Mode Auto, is it possible to stop the TreeNodeCheckedChanged event from firing if the type is ProductOption? I want to be able to select a Product node, even if none or some of the Options are checked or unchecked. I tried to handle it in the NodeCheckChanged event, but that's after the node's IsChecked property is updated.
The XamDataTree does not support discrete adjustment of the CheckBoxMode per node level within the node hierarchy or NodeLayout, (there is a CheckBoxSettingsOverride exposed from NodeLayout, but this is limited to applying discrete style and visibility for the associated checkbox).
This behavior may be possible, but would require a custom implementation; one possible approach could include applying CheckBoxVisibility to Visible and CheckboxMode of ‘Auto’ on the XamDataTree and hiding Checkboxes for the NodeLayout that you’ve defined for ProductOption, then creating an item template specifically for that NodeLayout to include its own Checkbox. The idea here would be that Checkboxes for this node level would behave independently, not selecting when an ancestor node is selected, and you could handle the checked state of these Checkboxes to also activate the checked state for its ancestor nodes.
I’ve included the following link for our documentation which details supported behaviors for the built in CheckBoxes available with the XamDataTree:
http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=xamDataTree_xamDataTree_Check_Boxes.html
And this link for further context on implementing customized NodeLayouts:
http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=xamDataTree_xamDataTree_Node_Layouts.html
You don’t necessarily need to use the XamContextMenu for obtaining the same behavior in your previous post, but it was the most convenient to use in this case and including built-in support for handing/cancelling its ContextMenu_Opening event and would require less code to implement.
Please let me know if you have any further questions.
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
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.
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?
Thanks,
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(); }}
Chris K.
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.