UIElement 已从 canvas.Children 集合中删除,但仍会绘制。这是为什么呢?
我尝试从 Canvas
中删除 UIElement
。但尽管它已从 canvas.Children 集合中删除,但仍然保留在画布上绘制。
你知道这个问题有什么解决办法吗?
I try to remove an UIElement
from the Canvas
. But although it is removed from the canvas.Children collection, is still remains drawn on the canvas.
Do you know any solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说的不真实一定是真实的,所以你必须使用工具来解决明显的矛盾。
第一个也是最传统的工具是调试器。您可以从字面上检查
Canvas
的Children
属性,看看该元素是否存在,即使您认为已删除它。这就是“信任但验证”原则。通常你不需要验证常识性的事情,但当你有矛盾时就该开始验证了。第二个工具 Snoop 非常强大,非常适合您的情况:
您可以使用工具在可视化树中找到流氓对象,查看其父级,查看其属性等。这可能会让您相信它确实仍然是可视化树的一部分,但可能不在您认为的位置。
What you say is not true must be true and so you will have to use tools to resolve the apparent contradiction.
The first and most traditional tool is the debugger. You can literally inspect the
Children
property of theCanvas
and see if the element is there even though you think you removed it. This is the "trust but verify" principle. Normally you don't have to verify common sense things but when you have a contradiction it's time to start verifying.The second tool, Snoop, is very powerful and ideally suited for your situation:
With this tool you can find the rogue object in the visual tree, see its parent, see its properties, etc. This might convince you that it is indeed still part of the visual tree, but perhaps not where you thought it was.