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

Dynamic connection validation

4 Answers 151 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Geoffrey
Top achievements
Rank 1
Geoffrey asked on 13 Nov 2015, 09:02 AM

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.

4 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 18 Nov 2015, 08:58 AM
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
0
Geoffrey
Top achievements
Rank 1
answered on 03 Dec 2015, 05:18 PM

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.

0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 08 Dec 2015, 04:30 PM
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
0
Geoffrey
Top achievements
Rank 1
answered on 09 Dec 2015, 04:14 PM

It works fine thanks a lot!

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

This is what i was looking for, thanks again

Tags
Diagram
Asked by
Geoffrey
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Geoffrey
Top achievements
Rank 1
Share this question
or