Hi guys,
While using a XamDataTree and trying to programmatically enter edit mode for a given node, I am running into the following issue:
If I call EnterEditMode or ScrollNodeIntoView for a XamDataTreeNode that is already visible in the tree, it will automatically scroll that node to either the top or the bottom of the view. This seems to be the desired behavior for nodes that were not previously in the view, but I feel like if a node is already in the view, then the tree should just keep its scroll position and not jump around.
Is there any way I can override this behavior and prevent the tree from scrolling a node into the view when it's already visible?
Thanks,
Andrew
Hello Andrew,
I have been investigating into the behavior you are describing, but I cannot seem to reproduce the behavior you are seeing where if a XamDataTree node is already in view, that the ScrollNodeIntoView or EnterEditMode methods scroll it further. I have tested this behavior against version 20.1.20201.26 in Infragistics for WPF 2020 Volume 1.
I am attaching the sample project I used to test this. Please test this sample project on your machine as this may further indicate why this behavior is happening on your end. If this behavior happens with the sample project, this indicates a difference in either the assembly versions you are referencing or potentially something environmental. If the sample project does work correctly though, this could indicate an issue with your application and it would be helpful if you can either modify the sample project I am sending you and send it back, or provide an isolated one of your own?
Please let me know if you have any other questions or concerns on this matter.
XamDataTreeScrollIntoViewTest.zip
Thanks for the quick response! I forgot to mention that I am using Infragistics for WPF v19.2 (19.2.20192.261). I ran the sample project as-is with v20.1, and everything worked correctly, then I also ran it with v19.2, and everything still worked correctly. So I'm guessing it's not environmental or version-specific.
Next, I started looking at my own project to try to nail down some more exact steps to reproduce the behavior and noticed the following: If I add a child node to an existing node (that is already in the view), and then immediately programmatically call EnterEditMore on the newly created node, the tree jumps around.
I modified the sample project to reproduce this behavior and to use Infragistics v19.2.
Thanks!
Thank you for your update on this matter.
I was able to reproduce the behavior you are seeing with the sample project you have provided, but this appears to be more of a timing issue between the addition of the node and when the actual XamDataTreeNodeControl “presenter” of the node is created, and as such, I would recommend moving the code that is trying to put the node into edit mode or scroll the node into a Dispatcher.BeginInvoke action. This will delay the code enough to let the XamDataTreeNodeControl be created, measured, and arranged.
For example, you can modify the Add New Child button click to look like the following and this will avoid the issue you are seeing:
private void AddNewChildNoteBtn_Click(object sender, RoutedEventArgs e) { SampleData newChild = vm.AddChildNode(vm.Data[30]); Dispatcher.BeginInvoke(new Action(() => { var items = tree.GetNodesFromItems(new object[] { newChild }, true); tree.EnterEditMode(items[0]); }), System.Windows.Threading.DispatcherPriority.Background); }
Yep, that solved the problem! Thanks!