Error “Specified element is already the logical child of another element”?

前端 未结 3 858
离开以前
离开以前 2021-02-13 12:22

I have a TabControl and each Tab can contain the same UI but with different data. In any tab the user can click on a button and bring up a popup. This sets a Style property to t

相关标签:
3条回答
  • 2021-02-13 13:03

    Make sure you're creating a new tab object and you're not trying to insert the same tab into the tab control a 2nd time. A control can only have 1 parent and it seems like the issue is you're trying to insert a tab into either 2 different containers, or more likely the same tab control twice.

    0 讨论(0)
  • 2021-02-13 13:09

    To not read all the above the short answer is: you need to change Content to Template (in your XAML either style or direct declaration of ContentControl).

    0 讨论(0)
  • 2021-02-13 13:10

    My problem was I was setting the Content in my Style, and Content cannot have more then one logical parent. I needed to move that to a Template instead. Since I didn't want to lose the base style, I set the content in the ContentTemplate property of the HeaderedContentControl (DraggablePanel in my code).

    +1 to Davy anyways for helping me walk through this.

    0 讨论(0)
提交回复
热议问题