Add Connector and change Offset on existing

4 posts, 0 answers
  1. Domenico
    Domenico avatar
    7 posts
    Member since:
    Mar 2012

    Posted 22 Jul 2015 Link to this post

    Dear Support,
    I'm very new with Telerik and I'm evaluating WPF Diagram in a new project for one of our most important customer.

    One of Custom Shape we have to build must implement the function to add Connectors (for example by a Context Menu acttivated command).

    The Shape has a linear aspect and adding commands are "Add connector on the Right" and "Add connector on the Left".

    Both adding methods recalculate Offset of exixsting connectors and then add a new connector, with the aim to have connectors regularly spaced along the Shape.

    Although I can see new connector and existing ones in the Shape Connectors List, the aspect of the rendered Shape does not change that is to say that I cannot see the new connector and exixsting ones do not change their position.

    Those commands ​must operate (change Offset) also on Connectors with Connections, so for now I discarded the way of Remove and Add Connectors in order to avoid to loose existing Connection.

    Where's my error?

    Thank you

    King Regards

     

    Domenico

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 23 Jul 2015 Link to this post

    Hello Domenico,

    Could you please send us some code, especially the part which adds / moves the Connectors ? Also, any snapshots of the desired and current result of your code. This way we would be better able to advice you.

    Regards,
    Petar Mladenov
    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. Domenico
    Domenico avatar
    7 posts
    Member since:
    Mar 2012

    Posted 23 Jul 2015 in reply to Petar Mladenov Link to this post

    Hi Petar,

    following the methods that add the connectors on the right and on the left. First step is to reposition existing connectors changing their offset and then add the new one with the AddLinearConnector method

    protected void OnAddConnectorOnRight(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
            {
                try
                {
                    var existingCustomConnectors = Connectors.Where(c => c.Name.StartsWith(BaseConnectorName)).ToList();

                    #region Reposition existing (on left side)
                    Enumerable.Range(0, this.LinearConnectorNumber).ToList().ForEach(index =>
                    {
                        var conn = existingCustomConnectors.SingleOrDefault(c => c.Name == string.Format(BaseConnectorStringFormat, BaseConnectorName, index));
                        if (conn != null)
                        {
                            conn.Offset = new Point((1 + index)/(double) (this.LinearConnectorNumber + 2), conn.Offset.Y);
                            //conn.CalculateRelativePosition(new Size(Width, Height));
                        }
                    });
                    #endregion

                    #region Add new connector on right side
                    AddLinearConnector(new Point((LinearConnectorNumber + 1.0) / (LinearConnectorNumber + 2), 0.5), LinearConnectorNumber);
                    #endregion

                    LinearConnectorNumber += 1;

            
                }
                catch (Exception exception)
                {
                    exception.ShowError();
                }
            }

     protected void OnAddConnectorOnLeft(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
            {
                try
                {
                    var existingCustomConnectors = Connectors.Where(c => c.Name.StartsWith(BaseConnectorName)).ToList();

                    #region Reposition existing (on right side)
                    Enumerable.Range(0, this.LinearConnectorNumber).ToList().ForEach(index =>
                    {
                        var conn = existingCustomConnectors.SingleOrDefault(c => c.Name == string.Format(BaseConnectorStringFormat, BaseConnectorName, index));
                        if (conn != null)
                            conn.Offset = new Point((2 + index) / (double)(this.LinearConnectorNumber + 2), conn.Offset.Y);
                    });
                    #endregion

                    #region Add new connector on left side
                    AddLinearConnector(new Point(1.0 / (LinearConnectorNumber + 2), 0.5), LinearConnectorNumber, 0);
                    #endregion

                    LinearConnectorNumber += 1;

                    this.UpdateLayout();
                }
                catch (Exception exception)
                {
                    exception.ShowError();
                }
            }

    private void AddLinearConnector(Point location, int index, int position = -1)
            {
                var newConnector = new RadDiagramConnector
                                   {
                                       Offset = location,
                                       Name = string.Format(BaseConnectorStringFormat, BaseConnectorName, index),
                                       BorderBrush = Brushes.Black,
                                       Background = Brushes.Black,
                                   };

                if(position < 0)
                    Connectors.Add(newConnector);
                else
                    Connectors.Insert(position, newConnector);

                //newConnector.CalculateRelativePosition(new Size(Width, Height));

            }

     

    I attched a screenShot of the Shape with two connectors. Adding one or more connector with above mentioned methods, while I can see new them in the Shape Connector collection (with right offset) the situation does not change in the rendered shape.

     Thanks

    Best regards

     

    Domenico

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Jul 2015 Link to this post

    Hi Domenico,

     I guess this has in common with any custom style you use in the application. Do you change the default template of the shapes, do you move/ change the ConnectorsControl from the template ? You can send us isolation or the custom styles in a new support thread where you are able to attach files. Thank you in advance for your cooperation.

    Regards,
    Petar Mladenov
    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
Back to Top