Adding a link

Hello.

I want create a link betwwen two nodes, but, i would to check before if is possible this link.

Now i was overrited the method OnLinkAdded, but when the link is created, if all conditions are not ok, i need remove the last link created. My questions are:

1.- is possible don’t paint the link before?. By example, i draw the link, chek the condtions and if they all all right paint the link, but if not ok, show a message without draw the link.

2.- Now if have the method: protected override void OnLinkAdded(Link link)

when i check the contions and they are bad, i execute this code:

ar model = this.Diagram.Model;
model.RemoveLink(link.FromData, link.FromPortId, link.ToData,link.ToPortId);

but i have the error:
No se puede cambiar ObservableCollection durante un evento CollectionChanged o PropertyChanged.

In english:
there is not possible change ObservableCollection while a event CollectionChanged o PropertyChanged. <br =“Apple-interchange-newline”>
The stacktrace:

en System.Collections.ObjectModel.ObservableCollection1.CheckReentrancy() en System.Collections.ObjectModel.ObservableCollection1.RemoveItem(Int32 index)
en System.Collections.ObjectModel.Collection1.Remove(T item) en System.Collections.ObjectModel.Collection1.System.Collections.IList.Remove(Object value)
en Northwoods.GoXam.Model.GraphLinksModel4.DeleteLink(LinkType linkdata) en Northwoods.GoXam.Model.GraphLinksModel4.DeleteLink(NodeType fromdata, PortKey fromparam, NodeType todata, PortKey toparam)
en Northwoods.GoXam.Model.GraphLinksModel4.RemoveLink(NodeType fromdata, PortKey fromparam, NodeType todata, PortKey toparam) en Northwoods.GoXam.Model.GraphLinksModel4.#yn(Object fromdata, Object fromparam, Object todata, Object toparam)
en SLRTC1201.Classes.Tools.RtcCustomPartManager.isLinkValid(Link link)
en SLRTC1201.Classes.Tools.RtcCustomPartManager.OnLinkAdded(Link link)
en Northwoods.GoXam.PartManager.AddLinkForData(Object linkdata, IDiagramModel model)
en Northwoods.GoXam.PartManager.OnModelChanged(ModelChangedEventArgs e)
en Northwoods.GoXam.Diagram.#oc(Object sender, ModelChangedEventArgs e)
en Northwoods.GoXam.Model.DiagramModel.OnChanged(ModelChangedEventArgs e)
en Northwoods.GoXam.Model.DiagramModel.#Fk(ModelChange change, Object data, Object oldval, Object newval)
en Northwoods.GoXam.Model.GraphLinksModel4.DoLinkAdded(LinkType linkdata) en Northwoods.GoXam.Model.GraphLinksModel4.#sm(Object sender, NotifyCollectionChangedEventArgs e)
en System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) en System.Collections.ObjectModel.ObservableCollection1.InsertItem(Int32 index, T item)
en System.Collections.ObjectModel.Collection1.Add(T item) en System.Collections.ObjectModel.Collection1.System.Collections.IList.Add(Object value)
en Northwoods.GoXam.Model.GraphLinksModel4.InsertLink(LinkType linkdata) en Northwoods.GoXam.Model.GraphLinksModel4.InsertLink(NodeType fromdata, PortKey fromparam, NodeType todata, PortKey toparam)
en Northwoods.GoXam.Model.GraphLinksModel4.AddLink(NodeType fromdata, PortKey fromparam, NodeType todata, PortKey toparam) en Northwoods.GoXam.Model.GraphLinksModel4.#rn(Object fromdata, Object fromparam, Object todata, Object toparam)
en Northwoods.GoXam.Tool.LinkingTool.DoMouseUp()
en Northwoods.GoXam.DiagramPanel.OnMouseLeftButtonUp(MouseButtonEventArgs e)
en Northwoods.GoXam.DiagramPanel.#Iz(Object s, MouseButtonEventArgs e)
en MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
en MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

THANKS.

Hello.
i have had exit doing:

IDiagramModel model = this.Diagram.Model;
RemoveLinkForData(link.Data, model);

Sorry and Thanks.

Yours.

As the documentation for PartManager.OnLinkAdded states:

[quote]The implementation of this method should not modify the model. This method
cannot and should not prevent or alter the addition of the link to the diagram.[/quote]
You really need to customize the link validation process, either by setting properties that cover many of the common cases, or by overriding the IsValidLink method on LinkingTool (and on RelinkingTool if your app permits it).

Thanks Walter. I will probe this on sunday :-)