gpt4 book ai didi

c# - "Element is already the child of another element."

转载 作者:行者123 更新时间:2023-11-30 19:11:51 27 4
gpt4 key购买 nike

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

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

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

(容器 = 另一个 StackPanel)

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

谢谢

最佳答案

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

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

关于c# - "Element is already the child of another element.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10019259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com