Dynamic validation

4 posts, 0 answers
  1. Vladimir
    Vladimir avatar
    11 posts
    Member since:
    Oct 2010

    Posted 09 Apr 2014 Link to this post

    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.
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 14 Apr 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vladimir
    Vladimir avatar
    11 posts
    Member since:
    Oct 2010

    Posted 15 Apr 2014 in reply to Zarko Link to this post

    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.




  5. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 18 Apr 2014 Link to this post

    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.

     
Back to Top