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

Dynamic validation

3 Answers 84 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 09 Apr 2014, 01:44 PM

I have created dynamic validation on scheme editing. But I encountered with few problems.
1) How to get active connection correctly? I use method described below:

01.private RadDiagramConnection GetActiveConnection()
02.{
03.    var toolService = ServiceLocator.GetService<IToolService>();
04.    if (toolService == null || toolService.ActiveTool == null) return null;
05. 
06.    var toolType = toolService.ActiveTool.GetType();
07.    var fieldInfo = toolType.GetField("activeConnection", BindingFlags.Instance | BindingFlags.NonPublic);
08.    if (fieldInfo == null) return null;
09.    return fieldInfo.GetValue(toolService.ActiveTool) as RadDiagramConnection;
10.}
2) Please, make tool interfaces from Telerik.Windows.Diagrams.Core public.
3) Please, make RadDiagramShapeBase.UpdateVisualStates() non internal.

3 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 14 Apr 2014, 11:46 AM
Hello Vladimir,
Here I'll try to answer all of your questions:
1) I'd like to ask you why do you need this connection ? As far as I understand you're getting the connection that the ConnectionTool is currently creating is that right ? If you handle the ConnectionManipulationCompleted event you'll get the same connection in its event args and I think that this is the better solution.
2) I'm glad to tell you that as of Q1 2014 the tool interfaces and classes are public.
3) The UpdateVisualStates method is protected internal so you can override it and if you want to change the visual state of a shape you can always do it like this:
VisualStateManager.GoToState(this.diagram.Shapes[0] as FrameworkElement, "SomeState", false);
I hope I was able to help you and if you have more questions feel free to ask.

Regards,
Zarko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Vladimir
Top achievements
Rank 1
answered on 15 Apr 2014, 12:20 PM
1) Well i need to change current connector shape color when mouse is over another connection. 
So my alg:
a) OnConnectionManipulationStartedEvent on source connector(here connection is null in args)
b) mouse over another connector
c) OnConnectorActivationChangedEvent handling(activate)
d) Dynamic validation between source and current connectors
e) if connection valid - do nothing otherwise change custom connection dependency property IsValid which across styles will make connection shape red  
Thats why i need reference on current connection before ConnectionManipulationCompletedEvent
2) Nice, thank you
3) I like your code style rules so overriding "standard" method UpdateVisualStates give me more freedom. I want to control current control state and react on your states updates.




0
Zarko
Telerik team
answered on 18 Apr 2014, 11:25 AM
Hi Vladimir,
Thank you for the explanation - it really seems that there's no straightforward way to implement your scenario. The only possible workaround at the moment is to inherit our diagram and override the PublishDiagramEvent:
public class MyDiagram : RadDiagram
{
    public IConnection CurrentConnection { get; set; }
    public bool IsConnectionCreation { get; set; }
 
    protected override bool PublishDiagramEvent(Windows.Diagrams.Core.DiagramEvent diagramEvent, object args)
    {
        if (diagramEvent == Windows.Diagrams.Core.DiagramEvent.ConnectionAdding && this.IsConnectionCreation)
        {
            var myArgs = args as GenericEventArgs<IConnection>;
            this.CurrentConnection = myArgs.Entity;
        }
        return base.PublishDiagramEvent(diagramEvent, args);
    }
}
and in code behind
private void OnConnectionManipulationStarted(object sender, ManipulationRoutedEventArgs e)
{
    this.diagram.IsConnectionCreation = true;
}
 
private void OnConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
{
    this.diagram.IsConnectionCreation = false;
}
We'll consider making the ConnectionTool's activeConnection property public for some of your next releases but at the moment those are your only options.
I hope I was able to help you and if you have more questions feel free to ask. 

Regards,
Zarko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Diagram
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Vladimir
Top achievements
Rank 1
Share this question
or