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
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);
}
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
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.
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
It works fine thanks a lot!
EventManager.RegisterClassHandler(typeof(MainWindow), RadDiagramConnector.ActivationChangedEvent, new RadRoutedEventHandler(OnConnectorActivationChanged))
This is what i was looking for, thanks again