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

GetConnectionContainerForItemOverride vs. ContainerGenerator_StatusChanged

4 Answers 51 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Jackey
Top achievements
Rank 1
Jackey asked on 18 Apr 2015, 11:25 AM

Hi team,

I am using custom Connectors and Connections along with MVVM. Per the thread, I can add some custom connection points in the overridden method GetConnectionContainerForItemOverride

protected override IConnection GetConnectionContainerForItemOverride(object item)
{
    if (item is Link)
    {
        ...

                return a custom connection object;

    }
 
    return null;
}

Meanwhile I want to attach the connection to my custom connectors inside this method. However, at this time, the connectors of the shape still are the 5 default connectors. Are there any means to control the sequence of the overwritten methods? Or I should overwrite another virtual method? 

Thanks,

Jingfei

4 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 20 Apr 2015, 11:27 AM
Hi Jingfei,

Could you elaborate a bit more on the scenario you have and the expected result you are trying to achieve.The approach mentioned n the thread you referred to is appropriate when you have custom shapes. If I understood you correctly you would like to connect your custom connectors with custom connections. If this is so, please check out our help topic regarding Custom Connections.

As for adding your own connectors using MVVM you will need to create an Attached property to the RadDiagramShape and bind its Value to a collection from your ViewModel. In the attached property you have direct access to the shape and its Connectors collection and you could add the new connections to the collection. Also you could choose to either ignore or use the default five connectors using the UseDefaultConnectors property of the shape.

Regards,
Peshito
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jackey
Top achievements
Rank 1
answered on 20 Apr 2015, 01:07 PM

Hi Peshito,

Thanks for your reply. I know how to use Attached Property to define custom connector along with MVVM. I paste the core piece of code here

public static void ConnectorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var connectors = e.NewValue as List<CustomConnector>;
            var shape = d as RadDiagramShapeBase;
            if (shape != null)
            {
                shape.Connectors.Clear();
                shape.UseDefaultConnectors = false;
                if (connectors != null)
                {
                    connectors.ForEach(connector => shape.Connectors.Add(new RadDiagramConnector() { Offset = connector.Offset, Name = connector.Name, Tag = connector.Name }));
                }
            }
        }

In this function, I can define custom connectors I want. However, I don't know how to define custom CONNECTIONS.  You know one RadDiagramConnection has a source connector and a destination connector. But, when running to this function, the target connectors might be absent. Event the target connectors are there, in this method, there are no ways to access those connectors which belong to other RadDiagramShapes. Correct me if I am wrong.

I've read Custom Connectors many times. I find no ways to integrate with MVVM. Please help me out! :)

 

0
Accepted
Peshito
Telerik team
answered on 21 Apr 2015, 10:40 AM
Hi Jingfei,

The RadDiagramConnection’s have two properties controlling to which connector they are connected - SourceConnectorPosition and TargetConnectorPosition. Despite the position in their name, they correspond to the Name property of the Connector. If you set these properties to the connections and connect them to the new connectors you will have the expected result. Please note that you need to set these properties once the diagram is loaded due to limitation in the current implementation. As the Connectors collection does not have a setter and you can’t bind it to a collection in your ViewModel, we use the approach with AttachedProperty like you did. Doing so the Connectors are not set after the styles are loaded and the value for their properties is requested, that is why also can’t bind the SourceConnectorPosition and TargetConnectorPosition directly in style as they are not yet created and such connectors does not exist.

Attached is a sample project illustrating the above.

Regards,
Peshito
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jackey
Top achievements
Rank 1
answered on 22 Apr 2015, 05:18 AM

Hi Peshito,

Thanks for your assistance. It works nicely. 

Tags
Diagram
Asked by
Jackey
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Jackey
Top achievements
Rank 1
Share this question
or