The MindFusion Forums
Flow Diagramming Components >> WPF >> Flip DrawingLink
https://mindfusion.eu/Forum/YaBB.pl?num=1549284150

Message started by Orlov_Valera on Feb 4th, 2019 at 12:42pm

Title: Flip DrawingLink
Post by Orlov_Valera on Feb 4th, 2019 at 12:42pm
Hi everyone I need customize DrawingLink - to flip it (turn over). As it on example picture 1.
By default I have next situation (as it is on picture 2)
But I need as it is on picture 3.

picture_1.jpg ( 25 KB | 143 Downloads )
picture_2.jpg ( 21 KB | 127 Downloads )
picture_3.jpg ( 21 KB | 126 Downloads )

Title: Re: Flip DrawingLink
Post by Slavcho on Feb 4th, 2019 at 5:20pm
Hi,

Are you applying a RenderTransform on the link or diagram? If you only want to move the arrowhead to the other side, set link's BaseShape property and clear HeadShape. If you need to actually reverse the link in the diagram's backing graph, save a copy of link.ControlPoints and reverse the list, then exchange the Origin and Destination references, and assign the reversed points back to ControlPoints.

Regards,
Slavcho
Mindfusion

Title: Re: Flip DrawingLink
Post by Orlov_Valera on Feb 5th, 2019 at 10:03am
Thank you for your reply. I have tried your advice.
If I reverse list of the link.ControlPoints then link change it direction.
If I save link.ControlPoints, reverse the list, exchange  the Origin and Destination references, assign the reversed points back to link.ControlPoints  then links is disappear. The reason why text is flipped because whole my form and diagram has FlowDirection = FlowDirection.RightToLeft (arabic version). So in fact I just need to change FlowDirection only for text, not for whole link.

Title: Re: Flip DrawingLink
Post by Lyubo on Feb 5th, 2019 at 1:02pm
Hi,

To keep the RightToLeft flow direction of the diagram and just flip link texts, you can try custom drawing the text and applying a scale transform to mirror it. Something like:

[code]diagram.LinkCreated += (s, e) =>
  {
      e.Link.CustomDraw = CustomDraw.Additional;
      e.Link.TextBrush = null;
      e.Link.Text = "my text";
  };

diagram.DrawLink += (s, e) =>
  {
      e.Graphics.PushTransform(new ScaleTransform(-1.0, 1,
          e.Link.Bounds.Left + e.Link.Bounds.Width / 2,
          e.Link.Bounds.Top + e.Link.Bounds.Height / 2));

      e.Graphics.DrawText(new FormattedText(e.Link.Text, CultureInfo.InvariantCulture,
        FlowDirection.LeftToRight, new Typeface(e.Link.FontFamily.Source), e.Link.FontSize, Brushes.Black), e.Link.Bounds.Location);

      e.Graphics.Pop();
  };[/code]

Regards,
Lyubo


Title: Re: Flip DrawingLink
Post by Orlov_Valera on Feb 5th, 2019 at 3:39pm
Thank you! That works fine! But LinkCreated event does not fire. Should I switch some property? If there is a way to trigger that text have been added to DiagramLink?

Title: Re: Flip DrawingLink
Post by Lyubo on Feb 6th, 2019 at 10:14am
Hi,

Are you creating the links in code? The event is raised only for interactively created links.

You can extract the handler code in a separate method and call it after creating the link and from the LinkCreated event handler. Alternatively, you can set the Diagram.LinkCustomDraw property, so that it affects all links.

Regards,
Lyubo

Title: Re: Flip DrawingLink
Post by Orlov_Valera on Feb 6th, 2019 at 11:36am
Hi!
Thank you for your help.
Yes, I'm creating links in the code. Diagram.LinkCustomDraw property works perfect! The event DrawLink fires only when add DiagramLink to the Diagram. In this moment there is an ability to create new text with suitable flow direction. During workflow I add text to the DiagramLink. Is there a way to call Draw method or somehow redraw DiagramLink - to fire DrawLink event - to draw suitable text?
For calling Draw method I need DrawingContext and RenderOptions. Could somebody give an example of calling that method?

Regards,
Valerii.

Title: Re: Flip DrawingLink
Post by Lyubo on Feb 6th, 2019 at 2:16pm
Hi,

The LinkDraw event is raised both after setting the link.Text in code and from inplace edit interaction in my test.

To force a repaint, you can try calling the InvalidateVisual method on the link.

Regards,
Lyubo

Title: Re: Flip DrawingLink
Post by Orlov_Valera on Feb 6th, 2019 at 3:36pm
Thank you!!! That help me a lot!!!!

Regards,
Valerii.

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.