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

How to Persist or Serialize Connection Properties

1 Answer 164 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 15 Mar 2015, 05:16 PM
When I create my shapes, I'm changing the style of the Connections to look like the first image where they say "True" and "False". The function CreateTrueConnection shows the properties I'm setting. When I save and then reload the diagram it looks like the 2nd picture, which only retains the green and red colors, but none of the other styling and more importantly NOT the Name property, which I use in function GetTrueTargetRow to figure out my workflow in code. How do I serialize that information into the diagram so it will reload the same way?

public
static void CreateTrueConnection(RadDiagram Diagram, RadDiagramShape Shape, String Label = "")
{
    RadDiagramConnection tc = new RadDiagramConnection();
 
    tc.Stroke = Brushes.Green;
    tc.StrokeThickness = 2;
    tc.AllowDelete = true;
    ((Telerik.Windows.Diagrams.Core.IDiagramItem)tc).Name = "TrueConnection";
    tc.SourceConnectorPosition = Telerik.Windows.Diagrams.Core.ConnectorPosition.Bottom;
    tc.ConnectionType = Telerik.Windows.Diagrams.Core.ConnectionType.Polyline;
 
    tc.StartPoint = new Point(Shape.Connectors["Bottom"].AbsolutePosition.X, Shape.Connectors["Bottom"].AbsolutePosition.Y);
    tc.EndPoint = new Point(Shape.Connectors["Bottom"].AbsolutePosition.X, Shape.Connectors["Bottom"].AbsolutePosition.Y + 100);
    tc.TargetCapType = Telerik.Windows.Diagrams.Core.CapType.Arrow2Filled;
    tc.Source = Shape;
 
    // Add the "True" Label
    if (Label != "")
    {
        System.Windows.Controls.Border brdr = new System.Windows.Controls.Border();
        System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
 
        lbl.Background = Brushes.Green;
        lbl.Foreground = Brushes.White;
        lbl.FontWeight = FontWeights.Bold;
        lbl.HorizontalContentAlignment = HorizontalAlignment.Center;
        lbl.Content = Label;
 
        brdr.BorderBrush = Brushes.DarkGreen;
        brdr.BorderThickness = new Thickness(2.0);
        brdr.CornerRadius = new CornerRadius(3.0);
        brdr.Child = lbl;
 
        tc.Content = brdr;
    }
 
    Diagram.AddConnection(tc);
}

public static dsdSteps.BIEFlowchartStepRow GetTrueTargetRow(dsdSteps StepData, IShape Shape)
{
    dsdSteps.BIEFlowchartStepRow trueTargetRow = null;
    foreach (var con in Shape.OutgoingLinks)
    {                       
        //|| ((RadDiagramConnection)con).Stroke == Brushes.Green  <-- Tried looking at the connection color to know if it's true etc... didn't work
        if ((con.Name == "TrueConnection" || con.Name == "StartConnection") && con.Target != null)
        {
            trueTargetRow = (from x in StepData.BIEFlowchartStep
                             where x.GUID == ((RadDiagramShape)con.Target).Id
                             select x).FirstOrDefault();
        }
    }
    return trueTargetRow;
}

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 18 Mar 2015, 09:32 AM
Hello Brandon,

I cannot be completely sure about your scenario but I suppose that you have a business item deriving from our LinkViewModelBase<NodeViewModelBase> and a SerializableGraphSource. Along, with that you have custom Style targeting the RadDiagramConnection component and in that style you have bindings that are not restored after you reload your diagram. If this is not the case I will need you to provide more information on our scenario. If however this is your case I know what the issue is and I know how you can approach it.

First let me try to explain the reasons behind the issue. As you know when you save the RadDiagram you actually serialize all the shapes. The issue actually origins from the serialization. This feature serializes concrete values of the properties only. It does not seriali binding expressions. This is why all the bound properties in your custom Style are not reapplied after reloading.

In order to overcome this limitation you need to manually serialize and deserialize all the properties that are bound in your custom styles. This includes styles targeting connections, shapes and container shapes. These actions are pretty straightforward. You can take a look at this article and follow the approach for serializing and deserializing the Title property.

Please apply this approach to all the properties that are bound in your custom Styles and let us know if the issue still occurs on your side.

Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Diagram
Asked by
Brandon Davids
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or