We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Essential Diagram [WPF] Screen coordinates for nodes

Thread ID:





89711 Sep 3,2009 09:28 AM UTC Sep 7,2009 09:51 AM UTC ASP.NET Web Forms (Classic) 4
Tags: DiagramWebControl
Pavel Vykhryst
Asked On September 3, 2009 09:28 AM UTC

Imagine that we have a diagram with one node.

I need to know screen coordinates for the node (also if a scrollbar is used)
I am going to use custom drawing between nodes and external controls ...

There are

But how to check current HorizontalOffset and VerticalOffset or handle scrolling events?

Also Diagram.PointToScreen() works with exception "Visual object not connected",
Diagram.View.Scrollview is hidden

Nikhil A [Syncfusion]
Replied On September 4, 2009 04:59 AM UTC

Hi Pavel,

The Diagram.View.ScrollToHorizontalOffset() and Diagram.View.ScrollToVerticalOffset() methods are just to scroll to the desired offset values.

To get the screen coordinates of the node, you can use the following code:

Point screen = Diagram.View.PointToScreen(new Point(node.LogicalOffsetX,node.LogicalOffsetY));

where node is the Node object whose screen coordibates you are finding. The LogicalOffsetX and LogicalOffsetY properties always return a positive value with respect to the diagram view and hence even when the scrollbars are used, this will return the proper screen coordinates.

Please let us know if there are any concerns.

Syncfusion WPF team

Pavel Vykhryst
Replied On September 4, 2009 09:07 AM UTC

That method does not work correctly when a scrollbar is used.
For example, when the node is out of the visible view (like screenX=-10 screenY=-10)

I dave to use

class DiagramTools
private const string propertyName = "Scrollviewer";

public static ScrollViewer ExtractScrollViewer(DiagramView view)
PropertyInfo prop = view.GetType().GetProperties(BindingFlags.Instance|BindingFlags.NonPublic).First(item=>item.Name.Equals(propertyName));
object value = prop.GetValue(view, null);
return (value as ScrollViewer);

Pavel Vykhryst
Replied On September 4, 2009 03:28 PM UTC

And the code above does not work if there are many DiagramControls on the grid

All DiagramViews share the same instance in Scrollviewer property :-(

Nikhil A [Syncfusion]
Replied On September 7, 2009 09:51 AM UTC

Hi Pavel,

The code which was mentioned earlier using Logical offsets does not give proper values when the node has negative offsets because the LogicalOffsets always return the position with respect to the positive axis. When the node is hidden and a scrollbar is active, (i.e. node has negative offsets) then the OffsetX and OffsetY properties itself can be used to point to the screen coordinates.

Therefore the following code can be used:

Point screenpoint = diagramView.PointToScreen(new Point(n.OffsetX, n.OffsetY));

Now when the node has negative offsets, then the appropriate screen coodinate will be returned. For eg. if node has offsetx as -10 , then this above mentioned code will return negative coordinates(-10)when converted to screen, as the node is out of view.

There is no need to get access to the scrollviewer as this requirement can be achieved in the above mentioned way.

Please let us know if we have missed out on something or if there are any other concerns.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon