Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Bring nodes in view (Read 3055 times)
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Bring nodes in view
Jun 2nd, 2010 at 9:04pm
Print Post  
I have a Silverlight tree control that lists all the nodes. When the user selects the node I select the node in the diagram (in code) this works fine. However, our users want the node to be brought in view if the selected node is not in the view.
Our diagram   Height="2880” Width="5120" and Bounds="0, 0, 2000, 3000".

How do we bring the selected node in view (in code) so the user does not have to use the scrollbar and find the selected node?


  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Bring nodes in view
Reply #1 - Jun 2nd, 2010 at 9:19pm
Print Post  
Try setting ScrollX = node.Bounds.X - scrollViewer.ActualWidth / 2, and corresponding values for Y and Height.
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Bring nodes in view
Reply #2 - Jun 2nd, 2010 at 10:26pm
Print Post  
This works great Stoyan. thank you for the quick reply.

(only if you get a chance can you please let me know how to add some animation and bring it slowly into view.. this is not a requirement from the users.. but you have something handy it might look better.. )
appriciate all your help.
thaks Don Almeida. 
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Bring nodes in view
Reply #3 - Jun 3rd, 2010 at 7:46am
Print Post  
Try using the following method.

Code
Select All
void ScrollAnimated(double x, double y, double seconds)
{
	var timer = new DispatcherTimer();
	int ticks = (int)(40 * seconds);
	double dx = (x - diagram.ScrollX) / ticks;
	double dy = (y - diagram.ScrollY) / ticks;
	timer.Tick += (s, e) =>
	{
		if (ticks-- == 0)
		{
			diagram.ScrollX = x;
			diagram.ScrollY = y;
			timer.Stop();
		}
		else
		{
			diagram.ScrollX += dx;
			diagram.ScrollY += dy;
		}
	};
	timer.Interval = TimeSpan.FromSeconds(1.0 / 40);
	timer.Start();
} 



e.g. call ScrollAnimated(newx, newy, 0.5);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Bring nodes in view
Reply #4 - Jun 3rd, 2010 at 2:33pm
Print Post  
Perfect.. this is amazing Stoyan.. you go beyond what your customer asks..

Thank you,
Don Almeida,
  

Don Almeida.
Back to top
 
IP Logged
 
Mathias Z.
YaBB Newbies
*
Offline


DiagramLite is cool!

Posts: 5
Joined: Sep 27th, 2010
Re: Bring nodes in view
Reply #5 - Oct 18th, 2010 at 4:46pm
Print Post  
Stoyo wrote on Jun 2nd, 2010 at 9:19pm:
Try setting ScrollX = node.Bounds.X - scrollViewer.ActualWidth / 2, and corresponding values for Y and Height.


Hello Stoyan,
I applied the algorithm you described. My intention was to have the node in the center of the diagram (embedded in the scroll viewer). I made two improvements, which I would like to share if anybody is interesed:
  • Add half the node's width (respectively height)
  • Take zoom level into consideration. I found out that the scroll viewer's actual height/width needs to be adjusted.

Taking this into consideration, my code looks like this:
ScrollX = node.Bounds.X + node.Bounds.Width/2 - scrollViewer.ActualWidth / (2.0 * diagramArea.ZoomFactor / 100.0)

Cheers

Mathias
  

Mathias
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint