“元素已经是另一个元素的子元素."

编程入门 行业动态 更新时间:2024-10-27 22:32:41
本文介绍了“元素已经是另一个元素的子元素."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

起初,这个例外对我来说没有意义.为什么我不能多次复制这个对象?但这不是重点:

At first, this exception doesn't really make sense to me. Why shouldn't i be able to duplicate this object multiple times? but thats not the point:

我使用列表.每当我导航到一个网站时,它应该这样做:

i use a List. Whenever i navigate to a site, it should do this:

 (App.Current as App).recent.ForEach(x => container.Children.Add(x));

(容器 = 另一个 StackPanel)

(container = another StackPanel)

第一次,它有效.之后,我得到了问题标题中显示的异常.我已经尝试使用列表框,但我刚刚收到一个 ArgumentException.我认为这些异常具有相同的来源,但我不知道我做错了什么.请帮忙

the first time, it works. afterwards, i get the exception displayed in the questiontitle. i already tried using a listbox, but i just got a ArgumentException. I think these exceptions have the same source, but i don't know what i'm doing wrong. please help

谢谢

推荐答案

错误很明显:一个 WPF/SL 控件一次只能属于 1 个父控件.

The error is quite clear: A WPF/SL Control can only belong to 1 Parent control at a time.

因此,当您离开页面时,您要么必须从其父级中删除控件,要么必须在此 ForEach 中创建(可能克隆)新控件.

So you'll either have to remove the Controls from their Parent when you are moving away from a Page or you'll have to Create (possibly Clone) new Controls in this ForEach.

这篇关于“元素已经是另一个元素的子元素."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

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

发布评论

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

>www.elefans.com

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