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

4 posts, 0 answers
  1. Mahmut
    Mahmut avatar
    22 posts
    Member since:
    Nov 2014

    Posted 26 Feb 2015 Link to this post

    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>
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 02 Mar 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mahmut
    Mahmut avatar
    22 posts
    Member since:
    Nov 2014

    Posted 03 Mar 2015 in reply to Pavel R. Pavlov Link to this post

    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.
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 05 Mar 2015 Link to this post

    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.

     
Back to Top