Visual Studio Developer Center > Visual Studio Forums > Visual Studio WPF Designer > Cancel from DialogPropertyEditor causes Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.
Ask a questionAsk a question
 

AnswerCancel from DialogPropertyEditor causes Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.

  • Thursday, October 29, 2009 7:19 PMJane C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello, I've created a DialogPropertyValueEditor that I've attached to a Items collection property. This editor works fine, I can add, insert, delete and move items in the collection. The problem occurs when user Cancels the dialog. In this case, I get:

    Element already has a logical parent. It must be detached from the old parent before it is attached to a new one. at MS.Internal.DocumentTreeManagers.ItemUpdater.ApplyDelta(INodeHost nodeHost, DeltaItemCollection delta, ModifiableDocumentTree root, DocumentNodeDictionary oldTable, Boolean updateTable, DocumentNodeDictionary deletedItems, Comparison`1 compare) at Microsoft.Windows.Design.Documents.Trees.DocumentTreeManager.ApplyDelta(Delta delta, Comparison`1 compare) at Microsoft.Windows.Design.Documents.Trees.ModelDocumentTreeManager.ApplyEditingScopeDelta(Delta delta, Boolean resetDamage) at Microsoft.Windows.Design.Documents.Trees.ModelDocumentTreeManager.OnEditingScopeAborted(ModelEditingScopeImpl scope) at Microsoft.Windows.Design.Documents.Trees.ModelDocumentTreeManager.ModelEditingScopeImpl.OnRevert(Boolean finalizing) at Microsoft.Windows.Design.Model.ModelEditingScope.Revert()

    I assume this occurs because I have modified items in the collection by removing and re-adding them, and then the Revert encounters a remove and tries to re-add the item. If I don't remove and re-add items in the collection, then the changes aren't propagated to the XAML.

    Let me know if you need more info. Thanks, Jane
    • Moved byChao KuoMSFTMonday, November 02, 2009 7:08 AMOff topic in vsx (From:Visual Studio Extensibility)
    •  

Answers

  • Friday, October 30, 2009 2:51 PMJane C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I think I figured it out.  When an item changes I was doing a remove and insert.   I need to do an insert and remove, so that the Revert when Cancel is called, it does not think I'm adding an item that already exists.  In addition, I had to make a copy of my object for insert.
    • Marked As Answer byJane C Friday, October 30, 2009 2:51 PM
    •  

All Replies

  • Friday, October 30, 2009 2:51 PMJane C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I think I figured it out.  When an item changes I was doing a remove and insert.   I need to do an insert and remove, so that the Revert when Cancel is called, it does not think I'm adding an item that already exists.  In addition, I had to make a copy of my object for insert.
    • Marked As Answer byJane C Friday, October 30, 2009 2:51 PM
    •  
  • Monday, November 02, 2009 7:06 AMChao KuoMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello, Jane
    You question is about WPF designer, and this forum is about visual studio extensibility or visual studio SDK related. So I moved your thread to WPF Designer forum.
    Thanks
    Chao