|
Hello. I would like some advice on the best way to go about nesting diagrams.
My app has multiple diagrams, each on their own UserControl and never more than one visible at a time. They tend to have dozens or possibly over a hundred nodes, all of which are TemplatedNodes (some that have fairly complex ControlTemplates), and many links between all of the nodes.
I want to create a new diagram that acts as an overview of the entire system and would therefore have nodes where each node is a view of one of the existing diagrams. There is no need for the child diagrams to accept mouse clicks when being viewed as a node on the overview diagram, however the child diagrams do have their nodes change colour depending on what the connected server is doing, and it would be nice for that to work on the overview diagram.
One way I tried to do this was to create a new Diagram instance, call LoadFromString() with the result from the child diagram's SaveToString(), go through all of the nodes to reattach the viewmodels, embed this new Diagram instance in a DiagramView, and place that in a simple TemplatedNode. This seems to work, however I was having stability issues where exceptions were occurring in the MindFusion code (which I haven't investigated yet), especially if I tried to move around the nodes on the overview diagram.
Another way I tried was to call CreateImage() on the child diagram, and then use the resulting BitmapSource as the Source of an Image placed in a simple TemplatedNode, and then update the bitmap once per second to be able to catch the colour changing nodes. Issues I found with this was that after a few minutes of calling CreateImage() once per second, eventually I received an OutOfMemoryException, and before receiving the exception, switching over to the original child diagram's UserControl I would notice that interacting with the original diagram was now incredible sluggish and would cause CPU usage spikes. The CPU usage spikes could be solved by calling Clone() before CreateImage(), but then the resulting image would lose all of the ControlTemplates and the memory issue still occurred. Also, since CreateImage() must be called from the Dispatcher, complex child diagrams would cause a short UI freeze.
What do you think is the best approach? Should I go back to creating an actual embedded Diagram and try to solve stability issues?
Thanks!
|