帆布WPF中 - 我如何检测从画布当一个元素被添加/删除?画布、帆布、元素、WPF

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

我创造了我自己的子类的标准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.

推荐答案

检查这个帖子 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

阅读全文

相关推荐

最新文章