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

Connector AbsolutePosition returning 0,0 in ShapeDeserialized

1 Answer 73 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Brandon Davids
Top achievements
Rank 1
Brandon Davids asked on 13 Aug 2013, 10:38 PM
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)
    {
        CreateTrueConnection(e);
        CreateFalseConnection(e);
    }
 
    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);
    Console.WriteLine(e.Shape.Connectors["Right"].AbsolutePosition.X.ToString());
    Console.WriteLine(e.Shape.Connectors["Right"].AbsolutePosition.Y.ToString());
    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;
    this.diagram.AddConnection(tc);
}

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 14 Aug 2013, 07:48 AM
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;
    this.CreateTrueConnection(shape);
    this.CreateFalseConnection(shape);
}
Could you please try this out and if you have further questions feel free to ask.

Regards,
Zarko
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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 >>
Tags
Diagram
Asked by
Brandon Davids
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or