Cancel a connection based on the target type.

4 posts, 1 answers
  1. Paul
    Paul avatar
    3 posts
    Member since:
    Dec 2013

    Posted 07 Dec 2013 Link to this post

    Hi,

    I am new to Rad Controls/Diagram and would like some help if possible.

    What I would like to do is cancel a connection between two items within the diagram based on the target's type.

    Is this possible, if so, how would I go about it?

    Thanks
    Paul.
  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 11 Dec 2013 Link to this post

    Hi Paul,

    I am happy to inform you that there is straightforward way to achieve your requirement. You can subscribe to the ConnectionManipulationCompleted event and check the e.Shape property. This holds the target shape. Furthermore, in order to cancel the connection all you need to do is to mark the event as handled like this:

    private void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
    {
        var targetShape = e.Shape as RadDiagramShape;
        if (targetShape != null && targetShape.Content.Equals("Test Shape 2"))
        {
            e.Handled = true;
        }
    }
    I hope this will help you. Please do not hesitate to ask if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Paul
    Paul avatar
    3 posts
    Member since:
    Dec 2013

    Posted 11 Dec 2013 Link to this post

    Hi,

    Thank you for the information.

    The content property is null for me using the example code that you have provided.

    So to be clear, what I would like to do if a user drops a  Cross and a Cross 2 from the toolbox and the user tries to connect these two together then I should cancel the connection and information the user that they cannot connect these two types together.

    Regards
    Paul.
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 14 Dec 2013 Link to this post

    Hello Paul,

    The earlier provided code serves to illustrate my words. I used the Content property for simplicity. In your particular case, you as a developer will need to evaluate if the user action is valid and if not you just need to mark the event as handled, in order to prevent that action.
    Regards,
    Pavel R. Pavlov
    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 >>
Back to Top