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

XmlParseException - The default connectors cannot be removed because connections are attached to it.

3 Answers 71 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Mahmut
Top achievements
Rank 1
Mahmut asked on 26 Feb 2015, 09:20 AM
Hi,
Connectors of some items are generated dynamically in run-time, so I tried to bind Connectors using Extension. Drag-drop process are definitely working good, but when I bind all diagram,before calling extension method, it throws exception "XmlParseException - The default connectors cannot be removed because connections are attached to it.".

Thanks in advance.

    public class ConnectorExtension
    {
 
        public static readonly DependencyProperty ConnectorsProperty =
            DependencyProperty.RegisterAttached("Connectors", typeof(List<ConnectorModel>), typeof(ConnectorExtension), new UIPropertyMetadata(null, new PropertyChangedCallback(ConnectorsChanged)));
 
 
 
        public static void SetConnectors(UIElement element, List<ConnectorModel> value)
        {
            element.SetValue(ConnectorsProperty, value);
        }
        public static List<ConnectorModel> GetConnectors(UIElement element)
        {
            return (List<ConnectorModel>)element.GetValue(ConnectorsProperty);
        }
 
 
        public static void ConnectorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var connectors = e.NewValue as List<ConnectorModel>;
            var shape = d as RadDiagramShapeBase;
            if (shape != null )
            {
                if (connectors != null)
                {
                    shape.UseDefaultConnectors = false;
                    shape.Connectors.Clear();
                    connectors.ForEach(connector => shape.Connectors.Add(new RadDiagramConnector() { Offset = connector.Offset, Name = connector.Name, Tag=connector.Name }));
                }
                else
                {
                    shape.UseDefaultConnectors = false;
                    shape.Connectors.Clear();
                }
            }
        }
      
    }
}

<Style x:Key="DynamicConnectorStyle" TargetType="telerik:RadDiagramShape">
    <Setter Property="Position" Value="{Binding Position, Mode=TwoWay}"/>
    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
    <Setter Property="Height" Value="{Binding Height}" />
    <Setter Property="Width" Value="{Binding Width}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="IsEditable" Value="False" />
    <Setter Property="StrokeThickness" Value="0" />
    <Setter Property="UseDefaultConnectors" Value="False"/>
    <Setter Property="extensions:ConnectorExtension.Connectors" Value="{Binding Path=Connectors,UpdateSourceTrigger=PropertyChanged}"/>
    <Setter Property="ContentTemplate" Value="{Binding Path=TemplateKey,Converter={StaticResource DataTemplateSelector}}" />
</Style>

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 02 Mar 2015, 01:36 PM
Hi,

The exception is self explained. There should be no connections attached to any connector in order to remove it. If there is a connection attached to any connector the exception will be thrown. You need to remove all links to a connector before removing the connector itself.

Regards,
Pavel R. Pavlov
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
Mahmut
Top achievements
Rank 1
answered on 03 Mar 2015, 08:02 AM
Hi Pavel,
Thanks for response. I understood the exception itself. Actually, it is weird. I put a breakpoint in the line where connectors are removed, but the line is not executed. In other words, throw exception before removing the connectors. I think there is a connector binded to connection, and I tried to remove this connector, but it is not. I know because I solved the problem. Real problem is visualization part, connections created before items. And connections are trying to find connectors which are binded, and they can't find.
0
Pavel R. Pavlov
Telerik team
answered on 05 Mar 2015, 11:26 AM
Hi,

You are right about that behavior. Please note that the RadDiagram should remove all connectors of a shape when the RadDiagramShape.UseDefaultConnectors property is set to false. This is why you need to remove all connections before setting that property to false.

Regards,
Pavel R. Pavlov
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
Mahmut
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Mahmut
Top achievements
Rank 1
Share this question
or