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

Add Connector and change Offset on existing

3 Answers 101 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Domenico
Top achievements
Rank 2
Domenico asked on 22 Jul 2015, 08:05 AM

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

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 23 Jul 2015, 10:49 AM
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
0
Domenico
Top achievements
Rank 2
answered on 23 Jul 2015, 11:12 AM

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

0
Petar Mladenov
Telerik team
answered on 24 Jul 2015, 07:22 AM
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
Tags
Diagram
Asked by
Domenico
Top achievements
Rank 2
Answers by
Petar Mladenov
Telerik team
Domenico
Top achievements
Rank 2
Share this question
or