GetConnectionContainerForItemOverride vs. ContainerGenerator_StatusChanged

5 posts, 1 answers
  1. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 18 Apr 2015 Link to this post

    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

  2. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 20 Apr 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 20 Apr 2015 in reply to Peshito Link to this post

    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! :)

     

  5. Answer
    Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 21 Apr 2015 Link to this post

    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.

     
  6. Jackey
    Jackey avatar
    71 posts
    Member since:
    Oct 2014

    Posted 22 Apr 2015 in reply to Peshito Link to this post

    Hi Peshito,

    Thanks for your assistance. It works nicely. 

Back to Top
UI for WPF is Visual Studio 2017 Ready