Silverlight:当面板的子级发生变化时获取事件

发布于 2024-11-04 11:22:28 字数 81 浏览 4 评论 0原文

添加或删除子项时,有没有办法从 Panel 获取事件? 我从 WrapPanel atm 获取。

Is there a way to get a event from a Panel when a child is added or removed?
I'm deriving from a WrapPanel atm.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-11-11 11:22:28

没有公共事件或受保护的覆盖来跟踪 Children 成员资格的更改。但是,Children 属性的成员资格更改最终将导致 LayoutUpdated 事件。

如果您只需要知道成员是否已更改,那么最后一个子项计数的简单副本就足够了。但是,如果您需要跟踪已添加或删除的成员,那么您将需要完成工作,维护影子集合,比较集合并确保您不会保留应从影子中删除的条目收藏。

请记住,由于各种其他原因,LayoutUpdated 可能会相当频繁地发生,因此您附加到它的任何代码都需要尽快完成。由于您对可视化树所做的任何更改也可能会触发另一个 LayoutUpdated ,因此需要小心以避免创建无限循环。

There is no public event or protected override that tracks changes Children membership. However a change in the membership of the Children property will ultimately result in a LayoutUpdated event.

If you just need to know if the members have been changed then a simple copy of the last count of children would suffice. However if you need to keep track of which members have been added or removed then you will have your work cut out for you, maintaining shadow collection, comparing the collections and ensure you don't hold on to entries that should be removed from your shadow collection.

Bear in mind that LayoutUpdated can happen fairly frequently for all sorts of other reasons so any code you attach to it needs be done as quick as possible. Since any changes you might make to the visual tree might also trigger another LayoutUpdated care is needed to avoid creating an infinite loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文