Connector AbsolutePosition returning 0,0 in ShapeDeserialized

2 posts, 0 answers
  1. Brandon Davids
    Brandon Davids avatar
    2 posts
    Member since:
    Mar 2010

    Posted 13 Aug 2013 Link to this post

    I am trying to create a couple connectors automatically when a shape is dragged onto the diagram. I am formatting them to be green and red and have a label that says True and False, that's not an issue. I basically want the True connector to attach to the "Right" connecter at the source and NOT connect to a target but just have the connector go out to the right by 20 pixels or something. This is simply creating a "stub" for the user to route to their next target. 

    For this post, we can only talk about the True connector. The problem I'm having is that I want to set the connectors EndPoint just to the right of the "Right" Connector by 20 pixels BUT the connectors AbsolutePosition is returning 0,0. I'm using the ShapeDeserialized event which might be the problem, as the shape is probably not actually on the grid yet.

    Here is the line of code I'm talking about:
        tc.EndPoint = new Point(e.Shape.Connectors["Right"].AbsolutePosition.X + 20, e.Shape.Connectors["Right"].AbsolutePosition.Y);

    Any suggestions are appreciated.

    private void diagram_ShapeDeserialized_1(object sender, Telerik.Windows.Controls.Diagrams.ShapeSerializationRoutedEventArgs e)
        if(e.Shape.OutgoingLinks.Count() == 0)
        if (e.Shape is IFlowchartStepUI)           
            ((IFlowchartStepUI)e.Shape).LoadStep(_stepsData, e.Shape.Id);
    private void CreateTrueConnection(Telerik.Windows.Controls.Diagrams.ShapeSerializationRoutedEventArgs e)
        RadDiagramConnection tc = new RadDiagramConnection();
        tc.Stroke = Brushes.Green;
        tc.StrokeThickness = 2;
        // Add the "True" Label
        var lbltrue = new System.Windows.Controls.Label();
        lbltrue.Style = this.FindResource("TrueLabelStyle") as Style;
        lbltrue.Content = "True";
        tc.Content = lbltrue;
        //tc.Position = new Point(750, 150);
        tc.SourceConnectorPosition = Telerik.Windows.Diagrams.Core.ConnectorPosition.Right;
        //tc.TargetConnectorPosition = Telerik.Windows.Diagrams.Core.ConnectorPosition.Auto;
        //tc.SourceCapSize = new System.Windows.Size(7, 7);
        //tc.TargetCapSize = new System.Windows.Size(7, 7);
        tc.ConnectionType = Telerik.Windows.Diagrams.Core.ConnectionType.Polyline;
        //tc.StartPoint = new Point(750, 150);
        tc.EndPoint = new Point(e.Shape.Connectors["Right"].AbsolutePosition.X + 20, e.Shape.Connectors["Right"].AbsolutePosition.Y);
        tc.TargetCapType = Telerik.Windows.Diagrams.Core.CapType.Arrow2Filled;           
        tc.Source = e.Shape;
  2. Zarko
    Zarko avatar
    755 posts

    Posted 14 Aug 2013 Link to this post

    Hi Brandon,
    The problem is that in the ShapeDeserialized method the shape still doesn't have a position and size. The easiest fix/workaround this is to wait for the loaded event and add the connections there:
    private void diagram_ShapeDeserialized_1(object sender, Telerik.Windows.Controls.Diagrams.ShapeSerializationRoutedEventArgs e)
        if (e.Shape.OutgoingLinks.Count() == 0)
            var shape = e.Shape as RadDiagramShape;
            if(shape != null)
                shape.Loaded += this.OnShapeLoaded;
        if (e.Shape is IFlowchartStepUI)
            ((IFlowchartStepUI)e.Shape).LoadStep(_stepsData, e.Shape.Id);
    private void OnShapeLoaded(object sender, RoutedEventArgs e)
        var shape = sender as RadDiagramShape;
        shape.Loaded -= this.OnShapeLoaded;
    Could you please try this out and if you have further questions feel free to ask.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top