How to be notified when diagram is done painting?

I have a need to create a bitmap of a diagram after it has been modified (by code) and once it is done painting. What event or method do I need to hook/override to be notified when the diagram has completed its refresh/paint?

Notes on my situation:
Model is new GraphLinksModel<FieldNode, String, String, ReferenceLink>();
Layout is Northwoods.GoXam.Layout.LayeredDigraphLayout();

The actual rendering is done in an internal thread, so I’m not sure that would make sense for you.

But you could try doing what you need in a Diagram.LayoutCompleted event handler.

BTW, if you are using Silverlight, if you want to create a bitmap, you probably want to use the bitmap only after the bitmap has been rendered, which you can do in an Action that you pass as the last argument to one of the overloaded methods DiagramPanel.MakeBitmap.

Already tried LayoutCompleted, and the nodes have not completely rendered yet. I am in WPF, not Silverlight.

This might give you some ideas: Rendering Completion event needed?.

Or: Wait for WPF render thread?.

I’m sure there’s a lot more you can find on the web about these topics.


I worked around this by using threads, somewhat complex, but accomplished what I was after. (I needed to modify the diagram programmatically, then grab an image/bitmap from the diagram.)
The trick was to use a worker thread to control the interaction back into the UI thread of the controls.
So, from the UI thread, kick off a thread that will dispatch back into the UI thread to update the diagram, then wait a bit, and dispatch another call to pull the bitmap from the diagram.
(In order to invoke the method on the UI thread, you must use the Dispatcher of a control on the form.)
Because the rendering/paint of the control is deferred to yet another thread by the control itself we must do the process in two invocations for each diagram to allow wait time: // 1. Call RefreshDiagram on the UI thread to update the diagram content // (wait until rendering is done) // 2. Call SnapshotDiagram to pull the bitmap of the painted diagram private void ProcessDiagrams() { try { lock (this) { _buildingDiagram = true; } FldDiagram.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDiagramDelegate(RefreshDiagram), FieldElem, FieldElem.FirstChild as XmlElement, null); // null for no fromPortID

while (_buildingDiagram)
System.Threading.Thread.Sleep(300); // wait to allow UI thread to repaint
FldDiagram.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new SnapshotDiagramDelegate(SnapshotDiagram), FilePath);
}
catch (Exception E)
{
string ErrorMessage = string.Concat("Error on ", FilePath, ": ", E.Message);
AppLogUtils.LogError(“DuckCreek.DiagramImage”, ErrorMessage);
}
}
}