Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Container in VirtualizingDiagram loses its children when adding a new node / updating bounds (Read 1024 times)
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Apr 14th, 2023 at 9:41am
Print Post  
Hi,

The described problems are different, but both cause containers to lose their children. Let me show this behavior using the attached test project.

1) When I try to add a data object to the list bound to the NodesSource, it appears in the container, but the rest of the objects appear outside. And, accordingly, the further arranging of the container items doesn't make sense. I expect to see the new node appear next to the rest of the items inside the container and will participate in the arranging too. Please click the "Add" button to reproduce this case.

2) The second case is updating the diagram Bounds, which is required when resizing nodes, adding new elements, etc. In ZoomToFit() I calculate and set the ZoomFactor so that the diagram will automatically resize based on the window size. Then I set the size of the diagram to the size of the container node:
Code
Select All
Rect bounds = _containerNode.Bounds;
...
Bounds = bounds;
 


As you can see, the first time it happens correctly. Then, if you press the "Arrange" button, the container will lose some of the nodes. How to make it so that when resizing / adding new diagram elements, this does not happen?

I would be grateful for any advice that will help make it all work correctly. Thanks!

Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #1 - Apr 14th, 2023 at 3:06pm
Print Post  
Hi Kostya,

Try this build for 1; VirtualizingDiagram wasn't updated for ContainerNode redesign from v3.8, and this should fix a few things -

https://mindfusion.eu/_beta/wpfdiag392.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #2 - Apr 17th, 2023 at 8:34am
Print Post  
Hi Kostya,

For 2, VirtualizingDiagram expects to be placed in ScrollViewer, and seems the scenario works when you replace the <Grid> element in VirtualizationView.xaml with <ScrollViewer> one (along with changing the _diagramView declaration in .cs file).

Quote:
I calculate and set the ZoomFactor so that the diagram will automatically resize based on the window size


If you will be zooming to fit whole diagram, there won't be any virtualization of the WPF visual tree happening anyway. So we guess you are using the VirtualizingDiagram class only for the data-binding support?

In such case you might be better off implementing your own binding, to avoid the complexity of handling the difference between virtual and actual / realized items. E.g. duplicate VirtualizingDiagram from source code and remove pooling and VirtualNode/VirtualLink code, or do something like https://mindfusion.eu/Forum/YaBB.pl?num=1306412889/1#1.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #3 - Apr 17th, 2023 at 8:40am
Print Post  
Hi Slavcho,

Thank you, this update really helped to correctly add a new node! By the way, let me also ask about adding new links. In the same test project I do this:
Code
Select All
            var link = new LinkData();
            link.Origin = (NodeData)Nodes[1];
            link.Destination = (NodeData)Nodes[2];
            link.Text = "123";
            Links.Add(link); 


The new link data appears in the data source, but not in the diagram. Is this also something not implemented yet, or should I update/refresh the diagram somehow after that?

Thanks,
Kostya
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #4 - Apr 17th, 2023 at 9:06am
Print Post  
Hi Slavcho,

Thanks for the second advice about the ScrollViewer. But you're right, the only requirement for VirtualizingDiagram at the moment is the ability to bind data (MVVM pattern). And it seemed that this is what we need, unlike the Diagram control. There were a lot of new issues when trying to migrate from WinForms Diagram to WPF VirtualizingDiagram, so it was an idea to stick with Diagram and have some "data adapter". Let me try this idea with a Diagram based control and maybe that will solve most of the problems.

Thanks,
Kostya
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #5 - Apr 17th, 2023 at 9:24am
Print Post  
Hi Kostya,

Indeed adding to LinksSource wasn't refreshing the viewport. This build should fix it -
https://mindfusion.eu/_beta/wpfdiag392.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Container in VirtualizingDiagram loses its children when adding a new node / updating bounds
Reply #6 - Apr 17th, 2023 at 10:47am
Print Post  
Hi Slavcho,

Thank you for the quick reply and the updated assemblies! It works now.

Kostya
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint