Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Keep link's textblock location when a node is move (Read 2564 times)
alexbisson
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: May 20th, 2010
Keep link's textblock location when a node is move
May 20th, 2010 at 7:22pm
Print Post  
Hi,

I've added a key down event on the diagram to let the user move a link's textblock with the arrow keys, by setting the TextBlock.Margin property.

However, when a node connected to the link is moved, the textblock goes back to its original position (center of the link).

Is there a way to keep the textblock's relative position when one of the connecting nodes is moved?

Thank you!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Keep link's textblock location when a node is
Reply #1 - May 20th, 2010 at 7:41pm
Print Post  
Hi,

If by chance you are using a custom link class, you can do that by overriding the UpdateTextLayout method. Otherwise I suppose we could add some property to let you override the label position easier.

Stoyan
  
Back to top
 
IP Logged
 
alexbisson
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: May 20th, 2010
Re: Keep link's textblock location when a node is
Reply #2 - May 21st, 2010 at 3:26pm
Print Post  
I've subclassed DiagramLink but an exception is thrown when an unconnected link is added..I've been able to reproduce it in a sample application:

1. Add a Diagram and NodeListView with a few shapes on a silverlight page

2. Set the property :
Code
Select All
Diagram.AllowUnconnectedLinks = false  



3. Create a custom Link class:

Code
Select All
public class LinkBase : DiagramLink
{
    public LinkBase(Diagram diagram) : base(diagram) { }
} 



4. Create a custom behavior class:

Code
Select All
public class DiagramBehavior : DrawLinksBehavior
    {
        public DiagramBehavior(Diagram diagram) : base(diagram) { }

        protected override DiagramLink CreateLink(DiagramNode origin, Point point)
        {
            LinkBase link = new LinkBase(Diagram);
            link.Origin = origin;
            return link;
        }
    }
 



5. Add:

Code
Select All
diagram.CustomBehavior = new DiagramBehavior(diagram); 



6. Now drag a node on the diagram, and draw a link pointing to nothing. Since AllowUnconnectedLinks is set to false, the link is deleted. However, a null reference is thrown in a method called by MindFusion.Silverlight.Diagram.RemoveItem().

This happens only when subclassing DiagramLink.

Are you able to reproduce this behavior? If so, is there a workaround?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Keep link's textblock location when a node is
Reply #3 - May 21st, 2010 at 5:48pm
Print Post  
Hi,

Change CreateLink to this:

Code
Select All
protected override DiagramLink CreateLink(DiagramNode origin, Point point)
{
	LinkBase link = new LinkBase(Diagram);
	link.Origin = origin;
	link.Destination = Diagram.Dummy;
	return link;
} 



Or add and use a constructor that calls the base DiagramLink(Diagram, node, point) constructor.

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


I love YaBB 1G - SP1!

Posts: 6
Joined: May 20th, 2010
Re: Keep link's textblock location when a node is
Reply #4 - May 21st, 2010 at 5:58pm
Print Post  
Works great. Smiley Thank you for your help!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint