This is a migrated thread and some comments may be shown as answers.

positioning the connection content

1 Answer 151 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
al asked on 21 Aug 2016, 11:02 AM

hi dear supporters,

i have used the connection content  and connection points to route the connection.

now, the connection content is positioned in the middle of the connection but i need to position it in other positions.

the image is attached.

my code is also here.

how can i get the needed position of the connection content.

        private void diagram1_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
            var image = new System.Windows.Controls.Image() { Source = new BitmapImage(new Uri("components/" + "conn"+ ".png",UriKind.Relative)) };
            System.Windows.Point startPoint= e.Connection.StartPoint;
            System.Windows.Point endPoint= e.Connection.EndPoint;
            double deltaX = Math.Abs(endPoint.X - startPoint.X);
            double deltaY = Math.Abs(endPoint.Y - startPoint.Y);
            image.Width = 0.8*Math.Max(deltaX,deltaY);
            image.Height = 5;
            TextBlock txt = new TextBlock();
            txt.Text = strSelectedComponent;
            StackPanel stpanel = new StackPanel();            
            Viewbox viewBox = new Viewbox() { Stretch = Stretch.None, Margin = new Thickness(-4) };
            viewBox.Child = stpanel;
            e.Connection.ConnectionPoints.Add(new System.Windows.Point(endPoint.X,startPoint.Y));
            e.Connection.Content = viewBox;

1 Answer, 1 is accepted

Sort by
Dinko | Tech Support Engineer
Telerik team
answered on 24 Aug 2016, 11:58 AM

The behavior explained in your post is not supported by the RadDiagramConnection content out of the box. In order to reposition the content of the connection in the desired position you can implement custom logic which won't be a straightforward task. There is a lot of cases you have to cover in order the content to be on the right/left side of the connection when the routing functionality of the RadDiagram is turn on.

An approach which I could give you for the case shown in the attached picture is to use the HorizontalContentAlignment (set it to Right) property of the connection and manually calculate the Margin of the ViewBox as is in your case. But still, this approach could work only in this case, as soon as you move any shape the content position won't be correct.

Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Asked by
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question