This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am attempting to create a new ShapeNode in C# that will be placed in the center of the diagram view-port. Is there a way to do this? Whenever i attempt to calculate the center X and Y position the node gets created off of the screen.
Thank you! |
|
|
Hello The DiagramBounds property actually returns the logical bounds of the diagram model. At the point you are getting the DiagramBounds, the model is probably empty meaning the logical size is 0. Rather than logically positioning the node in the physical center of the diagram, it is recommend to physically move the viewport of the diagram surface to view the diagram model in the center instead. The DiagramSurface has a method that makes this very easy: SizeToFit. This method adjusts the viewport to center the diagram and also zooms the canvas so the diagram fills the viewport. If you don't need the zooming, simply set DiagramSurface.Zoom back to 1.0. This will revert back to standard zoom, but also keep the diagram centered. Here is an example of how to do this which I've encapsulated in a method (ds is the DiagramSurface instance):
Please note, the SizeToFit method only works when the DiagramSurface control has been loaded. If you need to center the diagram at start up, you can simply call the method above using a dispatcher. For example:
Please let me know if you have any questions about this. Jason Fauchelle |
|
|
Thank you. This should work perfectly! |
|
|
I did manage to get a node to appear centered on the flowchart using the following code.
|
|
|
Great to hear you got it working. |
|