Managaing connection between items

14 posts, 0 answers
  1. Yoan
    Yoan avatar
    17 posts
    Member since:
    Jan 2012

    Posted 11 May 2012 Link to this post

    Hello , 

    is there a way to manage the connections between items , for example I want user not to be able to create more than "n" connections to an item , one thing that came in my mind was to handle the connection created event , but I did not suceed in handling it , because there wasn't such an event. Any ideas ? 

    Best regards,
    Yoan
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 14 May 2012 Link to this post

    Hi Yoan,

     Currently, there is no straightforward way to achieve this. I have logged this as a feature request in PITS here so you can track its progress.

    Greetings,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Shrikant
    Shrikant avatar
    38 posts
    Member since:
    Jul 2011

    Posted 14 May 2012 Link to this post

    Hi Alex,
    What about connection created event ?
    When User creates a connection between two shapes.
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 17 May 2012 Link to this post

    Hello,

     The closest event to what you are looking for is the ItemsChanged event, however it is raised too early to handle this behavior.

    Regards,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Shrikant
    Shrikant avatar
    38 posts
    Member since:
    Jul 2011

    Posted 21 May 2012 Link to this post

    Hi Alex,
    you are right, the event get raised too early & for each item change. So this is not a good choice
    You need to do something for this, there should be unique Events
    1. When your creating connections
    2. When connection created
    3. double or single click events for connection
    4. connection modified or modifying


    These events are more important when working on business application, I can not stay only with Item Changed event & writes my whole logic there.

    Looking for better reply.
    Thanks
  7. Yoan
    Yoan avatar
    17 posts
    Member since:
    Jan 2012

    Posted 21 May 2012 Link to this post

    Hi , sorry for late reply , which actually is part of an answer. I managed to do with this problem / not in the most beatiful way / , but after all it is some solution at this time. I really hope soon there will be unique events for each manipulation. My solution to those who need it :

    First , we register for the items changed event , which captures the moment of creating a connection , after this we bind the target of the connection in two way mode to a property of the ViewModel , called TargetShape. Each time a new connection is created we remove the bindings for the old connections , and we handle the event in this way only if the diagram has already been loaded , because if we handle the event during serialization the targets become "null"s because of the binding. That is my way of managing with connections , I have also made an event "TargetShapeChanged" , through which to do some other operations.

    Hope you like it , and use it if do not know other possibilities :)

    private void diagram_ItemsChanged(object sender, DiagramItemsChangedEventArgs e)
           {
               if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
               {
                   if (e.NewItems != null && e.NewItems.Count() > 0)
                   {
                       if (e.NewItems.FirstOrDefault() is RadDiagramConnection)
                       {
                           if (!isDiagramReloaded)
                           {
                               RadDiagramConnection con = (RadDiagramConnection)e.NewItems.FirstOrDefault();
     
                               foreach (RadDiagramConnection connection in diagram.Connections)
                               {
                                   IShape target = (IShape)connection.Target;
                                   connection.ClearValue(RadDiagramConnection.TargetProperty);
                                   connection.Target = target;
                               }
     
                               ViewModel.TargetShape = null;
     
                               Binding targetBinding = new Binding("TargetShape");
                               targetBinding.Source = this.DataContext;
                               targetBinding.Mode = BindingMode.TwoWay;
                               con.SetBinding(RadDiagramConnection.TargetProperty, targetBinding);
                           }
                       }
                   }
               }
  8. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 22 May 2012 Link to this post

    Hi,

     For the official release, we will be exposing two events, which can be handled. They will be raised respectively in the beginning and in the end of each connection manipulation - when creating a connection, when attaching, detaching from shape or when changing the end points of a floating connection. You will be able to handle these events and prevent the action from taking place. Stay tuned for the release.

    Greetings,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. Christian
    Christian avatar
    7 posts
    Member since:
    Sep 2010

    Posted 03 Aug 2012 Link to this post

    But the new event never have Target on its arguments.

    Regards
  10. Christian
    Christian avatar
    7 posts
    Member since:
    Sep 2010

    Posted 03 Aug 2012 Link to this post

    This is the code that I use to solve the Target Problem:
    private void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
    {
     var connectedShapes = diagram.GetOutgoingConnectionsForShape(e.Shape).Select(c => c.Target);           
     var test = connectedShapes.FirstOrDefault().Content;
     
     e.Connection.Target = connectedShapes.FirstOrDefault();
    }

    Hope it helps. 
  11. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 07 Aug 2012 Link to this post

    Hello,

     The event arguments provide some properties to determine the nature of the action that this event describes. For example, you can use the e.ManipulationStatus value to check whether the connections has been attached to a shape, detached from a shape or moved as a floating connection. If you need to check the target shape, you can use the e.Connector property, which represents the connector of the target. The connector itself has a Shape property that you can use to get the target shape reference.

    Regards,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Gary Paul
    Gary Paul avatar
    4 posts
    Member since:
    Jul 2012

    Posted 13 Aug 2012 Link to this post

    private void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
    {
        e.Handled = TestConnection(e.Connection, e.Connector);
    }
     
    private bool TestConnection(IConnection connection, IConnector targetConnector)
    {
        var connector = connection;
        var sourceShape = connection.Source;
        var sourceConnectorName = connection.SourceConnectorPosition;
        var targetShape = targetConnector.Shape;
        var targetConnectorName = targetConnector.Name;
     
        return false;
    }

     

     I setting up to test if a connection is legal. I have the info I need but how to I cancel the connection? I have tried setting Handled = true and false but the connection is always made. I would like return false from TestConnection and have the connection not occur.

    It would be very nice to show an X over the target Connector if it is not a legal connection.

     

     

     

     

  13. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 16 Aug 2012 Link to this post

    Hello,

     I believe you have in mind the scenario where you create a connection using a shape's connector and try to attach it to another shape. You do can handle the event args of the ConnectionManipulationCompleted event (e.Handled=true). However, please note that this action only determines whether the connection will be attached or not to the target shape. If you check, you would see that the connection is not attached. However, this would not revert the creation of the connection. If you want this as well, I would recommend removing the connection as a whole using the diagram remove methods or using the Undo mechanism.

    Greetings,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  14. Gary Paul
    Gary Paul avatar
    4 posts
    Member since:
    Jul 2012

    Posted 16 Aug 2012 Link to this post

    I will attempt to make this work, however, I still do not see a solution for the mouse over requirement of showing that a connection is invalid.
    As a feature enhancement I would like to see more complete information in the following scenarios:

    Connector Mouse Over: Raise a MouseOver Event providing these three properties at the root of the EventArgs:
    1) Source Connector (the connector on the other end of the Connection)
    2) The Connection itself
    3) The Target Cnnector (the connector the Mouse is over)
     
    ConnectionManipulation Completed should allow you to fail the connection and remove it from the diagram without addtional code.

    All in all I'm very happy with the Diagram Control, however there are many areas for it to mature in.

    Thanks to the team for all their good work!

    G
  15. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Aug 2012 Link to this post

    Hello Gary,

    I will wrap up our discussion here as well, in case the someone else encounters the same issues:

    First, we in order to provide visual feedback about a connector while it is active/inactive, the RadDiagramConnector.ActivationChangedEvent should be used. However as it doesn't allow you to cancel a connection, we've logged a feature request to provide a preview event to allow you to cancel a connection from attaching to a connector and will provide information about what is activating the connector.

    In the meantime you can try the approach demonstrated in the attached solution - the connectors are validated, visual feedback is provided for the invalidated connectors and one connector can only be attached to one connection.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner