指定的元素已经是另一个元素的逻辑子元素(Specified element is already the logical child of another element)

编程入门 行业动态 更新时间:2024-10-24 12:23:52
指定的元素已经是另一个元素的逻辑子元素(Specified element is already the logical child of another element)

这个问题与这个帖子有关。

Prism RegionAdapter - 删除然后添加视图

我对这个帖子的帖子被删除了我的管理员,说它已经回答了,我需要开始新的帖子。 如果你们中的任何人解决了这个问题,请告诉我。

我删除的帖子是......你是如何设法摆脱“指定元素已经是另一个元素的逻辑子元素。首先断开它。” 关闭事件的错误。 我尝试了同样的事情,关闭后我从文件窗格中删除了dockablecontent。 但它不会帮助我继续得到这个错误。 删除视图后,再尝试以与添加相同的方式再次添加视图,我收到此错误。

请帮助我,我不确定我错过了什么。 我浪费了太多时间试图绕过它,但没有运气。

这是我正在使用的代码:

<ad:DockableContent ... x:Name="viewRoot" IsCloseable="True" HideOnClose="False" Title="{Binding Title}"> <ContentControl Grid.Row="1" Content="{Binding View}"/> </Grid> </ad:DockableContent>

它在这里使用:

<ad:DockingManager x:Name="DockingManagerControl" Grid.Column="1"> <ad:ResizingPanel x:Name="MainResizingPanel" ResizeWidth="*" ResizeHeight="*" Orientation="Horizontal"> <ad:DockablePane ad:ResizingPanel.ResizeWidth="0.25*" prism:RegionManager.RegionName="ProjectBrowserRegion"/> <ad:ResizingPanel x:Name="PespectiveResizingPanel" ResizeWidth="0.75*" ResizeHeight="*" Orientation="Horizontal"> <ad:DocumentPane x:Name="DockablePaneControl"/> </ad:ResizingPanel> </ad:ResizingPanel> </ad:DockingManager>

查看内容绑定是来自单独的dll的UI元素,所以我没有它们作为View / ViewModel对。 所以我不能在这里使用ContentTemplate + DataContext方式。 事情很好地加载,但使用可以选择/取消选择这些视图。 因此,如果一个视图再次打开了视图选择对话框,那么我清除所有视图(我从DockablePaneControl Items.Clear()中删除它),并再次添加所选视图(DockablePaneControl Items.Add()),然后我得到这个错误。

This question is related to following thread. Prism RegionAdapter - Removing then Adding View

My post to this thread was deleted my admin, saying it was answered and I need to start new thread. Please let me know if any of you have solved this issue.

My deleted post was... How did you manage to get rid of "Specified element is already the logical child of another element. Disconnect it first." error with closing event. I tried the same thing, on closing I remove the dockablecontent from the documentpane. But it doesn't help I keep getting this error. Once I remove the view, and then later try to add it again the same way you are adding, I get this error.

Please help me, I am not sure what am I missing. I have wasted so much of time trying to get around it but no luck yet.

Here is the code I am using:

<ad:DockableContent ... x:Name="viewRoot" IsCloseable="True" HideOnClose="False" Title="{Binding Title}"> <ContentControl Grid.Row="1" Content="{Binding View}"/> </Grid> </ad:DockableContent>

It gets used inside this:

<ad:DockingManager x:Name="DockingManagerControl" Grid.Column="1"> <ad:ResizingPanel x:Name="MainResizingPanel" ResizeWidth="*" ResizeHeight="*" Orientation="Horizontal"> <ad:DockablePane ad:ResizingPanel.ResizeWidth="0.25*" prism:RegionManager.RegionName="ProjectBrowserRegion"/> <ad:ResizingPanel x:Name="PespectiveResizingPanel" ResizeWidth="0.75*" ResizeHeight="*" Orientation="Horizontal"> <ad:DocumentPane x:Name="DockablePaneControl"/> </ad:ResizingPanel> </ad:ResizingPanel> </ad:DockingManager>

View content bindings are UI element which comes from separate dlls, So I don't have them as View/ViewModel pair. So I can't use ContentTemplate+DataContext way here. Things load nicely, but use can select/deselect these views. So if a view has been opens the view selection dialog again, then I clear all views (I remove it from DockablePaneControl Items.Clear()), and add the selected views again (DockablePaneControl Items.Add()), then I get this error.

最满意答案

通常这是因为您尝试将同一控件分配给两个不同的父项。

我经常在Styles中看到这个问题,其中包含Controls的非模板属性在Style中设置,例如ContentControl.Content或DataGridColumn.Header

例如,如果您的样式设置了ContentControl.Content ,并且向窗口添加了两个ContentControl,则会遇到此错误,因为样式正在尝试在两个ContentControl的“ Content部分中分配相同的控件。 修复方法是设置模板样式,例如ContentControl.ContentTemplate而不是ContentControl.Content 。 我想说这就像给多个人一样的cookie - 它只是不起作用。 你必须给他们每个饼干切割器(模板),以便他们可以自己做。

我实际上看到有关此错误的问题,以至于我写了一篇关于它的博客文章

Usually this occurs because you are trying to assign the same control to two different parents.

I often see this issue with Styles, where a non-template property that contains Controls is set in a Style, such as ContentControl.Content, or DataGridColumn.Header

For example, if your style sets ContentControl.Content, and you add two ContentControls to your Window, you'll encounter this error because the style is trying to assign the same controls inside the Content section of both ContentControls. The fix is to set a template style, such as ContentControl.ContentTemplate instead of ContentControl.Content. I like to say this is like giving multiple people the same cookie to it - it just doesn't work. You have to give them each the cookie cutter (template) instead so they can make their own.

I actually see questions about this error so much that I wrote a blog post about it

更多推荐

本文发布于:2023-08-06 05:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   逻辑   element   logical   child

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!