Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DiagramLink ControlPoints property (Read 3215 times)
binuvc
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 46
Joined: Nov 7th, 2011
DiagramLink ControlPoints property
Nov 9th, 2011 at 12:48pm
Print Post  
Hi,

I am having an object model representing my nodes and links. I have created the shapenodes anddiagramlinks from code and I am trying to do a two way binding to the properties of my object model.

Shape node supports binding to the HeightProperty and WidthProperty. But the DiagramLink ControlPoints is not supporting binding. Is there any way by which I can achieve the same.

Please advice.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramLink ControlPoints property
Reply #1 - Nov 9th, 2011 at 1:41pm
Print Post  
Hi,

The only way I can think of doing that currently is to create a custom DiagramLink class that adds a new dependency property for binding and overrides UpdateVisuals to update the property. UpdateVisuals is called every time the link points change their position. For binding in the other direction, you could update ControlPoints from the OnChanged callback you register with the custom dependency property.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
binuvc
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 46
Joined: Nov 7th, 2011
Re: DiagramLink ControlPoints property
Reply #2 - Mar 29th, 2012 at 6:38am
Print Post  
Hi,

Is this possible with the latest version 2.3.1 ?

We would really like to avoid creating a custom link for the same. Smiley

If not supported by the latest version too, could you please provide some insight in to what the UpdateVisuals does. Preferrably some sample code to achieve the same would be helpful.

Thanks
BinuVC
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramLink ControlPoints property
Reply #3 - Mar 30th, 2012 at 7:31am
Print Post  
Here's a sample class:

Code
Select All
class BoundLink : DiagramLink
{
	public BoundLink(Diagram diagram, DiagramNode origin, DiagramNode destination)
		: base(diagram,origin, destination)
	{
		updating = true;
		Points = new List<Point>(ControlPoints);
		updating = false;
	}

	public List<Point> Points
	{
		get { return (List<Point>)GetValue(PointsProperty); }
		set { SetValue(PointsProperty, value); }
	}

	static public DependencyProperty PointsProperty = DependencyProperty.Register(
		"Points", typeof(List<Point>), typeof(BoundLink), new PropertyMetadata(null, OnPointsChanged));

	private static void OnPointsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
		var link = (BoundLink)d;
		link.OnPointsChanged();
	}

	private void OnPointsChanged()
	{
		if (updating)
			return;

		updating = true;
		SegmentCount = Points.Count - 1;
		ControlPoints.Clear();
		ControlPoints.AddRange(Points);
		UpdateFromPoints();
		updating = false;
	}

	protected override void UpdateVisuals()
	{
		base.UpdateVisuals();

		if (updating)
			return;

		updating = true;
		Points = new List<Point>(ControlPoints);
		updating = false;
	}

	bool updating;
} 



Above binding will work when you assign a new list to Points, but will not detect adding new points to the list. If you need that, you must use a list class that implements INotifyCollectionChanged, and handle its CollectionChanged event to refresh the link points. E.g. a Silverlight list class that already implements this interface is ObservableCollection.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint