Dynamic connection validation

5 posts, 1 answers
  1. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 13 Nov 2015 Link to this post

    Hello,

    I'm using RadDiagram and i have validation rules for create link depend of connector source, connector target, shape source and shape target.

    I find a way to do that with ConnectionManipulationCompleted and it works but i want do that verification during the creation, change cursor when the rules aren't valid.

    There is no ConnectionManipulating event as Dragging in DraggingService and i didn't find a connectionService that give me this kind of event

    I want to do the same thing than http://www.telerik.com/forums/dynamic-validation but i think i miss something

    Can someone help me please?

    Thank you in advance.

  2. Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 18 Nov 2015 Link to this post

    Hi Geoffrey,

    If I understood correctly, you want, to change the Cursor appearance when you enter a Connector  while dragging a Connection and the rules are invalid. To achieve this, you can create a custom class which inherits RadDiagramConnector and override its MouseEnter method.
    protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
    {
        if ( rules are invalid )
            this.Cursor = Cursors.No;
        else
            this.Cursor = Cursors.Pen;
     
        base.OnMouseEnter(e);
    }
    Then you can add the custom connectors to the RadDiagramShapes. 
    foreach (var item in this.diagram.Shapes)
        {
            (item as RadDiagramShape).UseDefaultConnectors = false;
               // add custom connectors to the shape using its Connectors collection
         // for example: item.Connectors.Add(new MyCustomConnection());
        }

    Please, give this approach a try and let me know if you need any further assistance.

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 03 Dec 2015 Link to this post

    Thank you for your anwser,

    I do what you tell me but i have a problem, when you are creating a link, MouseEnter is not raise even if your cursor is on a target CustomConnector and this CustomConnector border getting red.

    Do you have another idea? 

    Do you want a simple program to verify what i say ?

     

    Thank you in advance.

  5. Answer
    Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 08 Dec 2015 Link to this post

    Hi Geoffrey,

    By design the diagram control is highly customizable and you can change a lot of its default behaviors. I attached a sample project that has a runtime connection validation. Basically, you can start a connection only from a right connector and you can end it only in a left connector. Also, each connector can have only one connection. As I mentioned in my previous reply, you can create a class which inherits RadDiagramConnector and override its MouseEnter method. Then you can create custom connectors on the RadDiagramShape using this custom class. To prevent creating a new connection on connector click (or prevent attaching a connection) from (or to) an invalid connector you can subscribe for the ConnectionManipulationStarted and ConnectionManipulationCompleted events of RadDiagram.

    I've attached a sample project showing a possible approach which I hope is a good starting point. So, could you please examine it and if you have more questions feel free to ask. You can manually modify the project to fit the desired scenario.

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 09 Dec 2015 Link to this post

    It works fine thanks a lot!

    EventManager.RegisterClassHandler(typeof(MainWindow), RadDiagramConnector.ActivationChangedEvent, new RadRoutedEventHandler(OnConnectorActivationChanged))

    This is what i was looking for, thanks again

Back to Top
UI for WPF is Visual Studio 2017 Ready