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
Diagram.View.ScrollToHorizontalOffset()
Diagram.View.ScrollToVerticalOffset()
methods.
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
NA
Nikhil A
Syncfusion Team
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.
Regards,
Nikhil
Syncfusion WPF team
PV
Pavel Vykhryst
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);
}
}
PV
Pavel Vykhryst
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 :-(
NA
Nikhil A
Syncfusion Team
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.
Regards,
Nikhil