Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) Moving link lables (Read 16410 times)
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Moving link lables
Jul 19th, 2010 at 7:29pm
Print Post  
Hi Stoyan,
We are using 1.5.0.29274 version of Diagram Lite and version 3 of Silverlight.
We used to use JGO controls form Northwoods before and in those controls our users were able to move link  labels around the link to make the make the workflow presentable. what is the best way to do this in Diagram lite. some of our users who have very crowded workflows would like to have this feature.
[img][/img]
to create a link I use this code:

DiagramLink link2 = diagram.Factory.CreateDiagramLink(fromNode, toNode);

link2.TextBrush = routeTextBrush;
link2.Style = procPrefs.StrightLines ? LinkStyle.Polyline : LinkStyle.Bezier;
                       
link2.Text = route.Description;
link2.Dynamic = true;
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #1 - Jul 20th, 2010 at 4:45pm
Print Post  
Hi Don,

You might override DiagramLink.UpdateTextLayout to place the TextBlocks at user-defined positions by setting TextBlock.Margin. You can add mouse event handlers to the links' TextBlocks to implement drag support, or do that by adding temporary nodes when in label-move mode and handle NodeModified for these nodes to set the custom label position.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #2 - Jul 23rd, 2010 at 1:16pm
Print Post  
This example implements moveable link labels:
https://mindfusion.eu/_samples/MoveLabels.zip

You must set a link's IsTextMovable property to let the user move its label.

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


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #3 - Aug 4th, 2010 at 6:26pm
Print Post  
Hey Stoyan, I get this error when i compile this code in my environment. am I missing something?

Error1'CustomLink.CustomDiagramLink.UpdateTextLayout()': cannot override inherited member 'MindFusion.Diagramming.Silverlight.DiagramLink.UpdateTextLayout()' because it is not marked virtual, abstract, or overrideC:\Dev\Research\Almeida\MoveLabels\CustomDiagramLink.cs10133CustomLink
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #4 - Aug 5th, 2010 at 5:22am
Print Post  
Hi,

Check the PM page and try that with the new build linked there.

Stoyan
« Last Edit: Aug 5th, 2010 at 8:07am by Stoyo »  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #5 - Aug 6th, 2010 at 3:43pm
Print Post  
I have upgraded everything and it works fine.. however when the user tries to draw a link.. the users gets a type cast exception at

private void diagram_LinkCreated(object sender, LinkEventArgs e)
       {
           [b]CustomDiagramLink link = (CustomDiagramLink)e.Link;[/b]
            ......

is there a better way to cast DiagramLink to CustomDiagramLink?
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #6 - Aug 6th, 2010 at 3:48pm
Print Post  
You could typecast as shown below if your application supports more than one type of links.

Code
Select All
var customLink = e.Link as CustomDiagramLink;
if (customLink != null)
{
	......
} 



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


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #7 - Aug 6th, 2010 at 4:07pm
Print Post  
I tried that but it always comes back as null..
CustomDiagramLink link = e.Link as CustomDiagramLink;
           if (link != null)
            {}

  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #8 - Aug 6th, 2010 at 4:59pm
Print Post  
Have you assigned the custom behavior class from the sample to diagram.CustomBehavior?
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #9 - Aug 12th, 2010 at 3:12pm
Print Post  
Yes I did set the diagram.CustomBehavior and that problem is solved but another one showed up. (Earlier I had the drawlinks behavior) now when the user drags the mouse new nodes are created. We don’t want the user to draw nodes in this fashion hence draw links worked for us. What do you suggest we do so the user can’t draw nodes by dragging the mouse?
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #10 - Aug 12th, 2010 at 3:33pm
Print Post  
Try deriving the custom behavior class from DrawLinksBehavior instead of LinkShapesBehavior.

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


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #11 - Aug 12th, 2010 at 3:38pm
Print Post  
wow.. that works.. you know everything.. and you are so fast.. thanks Don Almeida.
  

Don Almeida.
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #12 - Aug 12th, 2010 at 9:26pm
Print Post  
Hi Stoyan,
When we double click the link we open a properties dialog with the link properties etc.. somehow when we double click the textblock nothing happens. how can I run the same handler
diagram_LinkDoubleClicked(object sender, LinkEventArgs e) when the user double clicks the textblock
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #13 - Aug 13th, 2010 at 5:29am
Print Post  
Hi Don,

We'll try to add built-in support for this in the next version. It can be done in the current version too, but will be a little tricky. First you would have to associate TextBlocks with their links, e.g. using the TextBlock.Tag property or a hashtable. Then add a TextBlock.MouseLeftButtonDown handler that tracks the last click position and time (using DateTime.Now). If the current click happens at the same position and say within half second of the previous click, call diagram.RaiseDoubleClicked(link, ...) to get the LinkDoubleClicked event raised.

Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #14 - Aug 17th, 2010 at 2:12pm
Print Post  
Thank you Stoyan, I will try that.. but in the mean time whe I try to copy a link i get this exception below....
I use this code to copy..

copyData = currentDiagram.CopySelection(true)



System.NullReferenceException: Object reference not set to an instance of an object.
at MindFusion.Diagramming.Silverlight.DummyConnectionPoint..ctor([u][b]DiagramLink link[/b][/u], Boolean incoming, Point point)
at MindFusion.Diagramming.Silverlight.DummyNode.CreateConnectionPoint(DiagramLink link, Point point, Boolean incoming)
at MindFusion.Diagramming.Silverlight.ConnectionPoint.x8b61531c8ea35b85(DiagramLink
x4928e4bd9d929129, DiagramNode x2e1df3070e13eca2)
at MindFusion.Diagramming.Silverlight.Diagram.CopySelection(Boolean unconnectedLinks)
at ProcessDesigner.MainPage.CopySelection()
at ProcessDesigner.MainPage.DesignerContextMenuClick(Object sender, RadRoutedEventArgs e)
at Telerik.Windows.Controls.MenuBase.OnItemClick(RadRoutedEventArgs args)
at Telerik.Windows.Controls.MenuBase.OnItemClick(Object sender, RadRoutedEventArgs args)
at Telerik.Windows.RadRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
at Telerik.Windows.Controls.RadMenuItem.OnClickImpl()
at Telerik.Windows.Controls.RadMenuItem.OnClick()
at Telerik.Windows.Controls.RadMenuItem.ClickItem()
at Telerik.Windows.Controls.RadMenuItem.HandleMouseUp()
at Telerik.Windows.Controls.RadMenuItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}
  

Don Almeida.
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint