帆布WPF中 - 我如何检测从画布当一个元素被添加/删除? [英] Canvas in WPF - How do I detect when an element has been added/removed from the canvas?

查看:355
本文介绍了帆布WPF中 - 我如何检测从画布当一个元素被添加/删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了我自己的子类的标准WPF画布,以支持各种附加功能,在那些我想管理画布上的元素的Z-指数,但为了做到这一点,我需要运行一些$ C $ Ç每当一个元件被添加或删除至/从画布。遗憾的是没有画布,也不是儿童性似乎有相应的事件来处理这些情况。

I created my own subclass from the standard WPF canvas to support various additional functions, amongst those I wanted to manage the Z-Index of the elements on the canvas, but in order to do that I need to run some code whenever an element is added or removed to/from the canvas. Unfortunately not the canvas nor it Children property seem to have appropriate events to handle these cases.

什么是解决这一问题的最好/最简单的方法是什么?现在我手动调用一个方法,从任何地方在我的code我添加/删除一些东西之外,但这是相当哈克,不是很不错的的code未来的重用。

What would be the best/simplest way to fix this? Right now I call a method manually from the outside from wherever in my code I'm adding/removing something, but that's quite "hacky" and not very nice for future reuse of the code.

推荐答案

检查<一href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5f68b0c2-bda4-4856-91ab-e39ef3d143ed/"相对=nofollow>这个帖子 MSDN上,我觉得这回答你的问题。

Check this post on MSDN, I think it answers your question.

至于你的问题,我觉得你可以尝试覆盖OnVisualChildrenChanged()当孩子被添加,它可以解决您的问题,更多的细节,你可以参考一下:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d8933264-0958-499f-b6cd-41d61713ac8e

As for your problem, I think you can try to override the OnVisualChildrenChanged() when the child is added, it can resolve your issue, more details you can refer to: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d8933264-0958-499f-b6cd-41d61713ac8e

这篇关于帆布WPF中 - 我如何检测从画布当一个元素被添加/删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆