如何知道何时在 Silverlight 中添加了新的 UIElement

发布于 2024-07-17 11:56:05 字数 180 浏览 4 评论 0原文

我正在 sliverlight 中设计一个继承自 canvas 的用户控件。 我有必要找出新的 UIElement 何时添加到 MyBase 的 Children 属性,但没有像“ItemAdded”这样的事件。 由于我想为画布的子级设置动画,因此我无法使用 LayoutUpdated 事件(它已被点击一百万次)。

I am designing a user control in sliverlight that inherits from canvas. It is necessary for me to find out when a new UIElement is added to Children property of MyBase but there is no event like "ItemAdded". Since I want to animate the children of my canvas, I can not use LayoutUpdated event (It is hit a million times).

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

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

发布评论

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

评论(2

余生一个溪 2024-07-24 11:56:05

当添加/删除子级画布时,它会自动失效,以便发生测量/排列循环。 因此您不需要显式跟踪添加/删除操作。

相反,您只需要重写 MeasureOverride 方法,然后在该方法内您可以查看 Children 集合并注意发生了什么变化。 这是 Silverlight 比 WPF 更难使用的地方。 您无法像 WPF 一样提供自己的集合来存储子项,也无法在现有的 Children 集合上挂钩事件。

When a child is added/removed the Canvas it will automatically be invalidated so that a Measure/Arrange cycle occurs. So you do not need to explicitly track the adding/removing operations.

Instead you just need to override the MeasureOverride method and then inside the method you can look at the set of Children and notice what has changed. This is one area that Silverlight is much harder to use than WPF. You cannot provide your own collection for storing children like WPF and cannot hook event on the existing Children collection.

起风了 2024-07-24 11:56:05

请注意,我没有 Silverlight 经验,但在 WPF 中,您可以在控件上使用 Loaded 和 Initialized 事件。

有关来自 MSDN 的 Mike Hillberg 的博客的详细信息

初始化事件

Initialized 事件通常会触发
当一个元素的属性有
一切都已设定。 具体来说,
框架元素/框架内容元素
实现 ISupportInitialize,并且何时
该接口的 EndInit 方法
被称为 IsInitialized 属性
设置为 true,并且已初始化
事件被触发。

已加载事件

当元素被加载时会触发 Loaded 事件
不仅被初始化,而且
即将被渲染。 动机
Loaded 事件是典型的
你想做一些事情的场景
在您的应用程序中初始化
加载时间。

Note that I have no Silverlight expierence, but in WPF you can use the Loaded and Initialized events on a control.

More info on a blog from Mike Hillberg from MSDN

Initialized Event

The Initialized event typically fires
when the properties of an element have
all been set. Specifically,
FrameworkElement/FrameworkContentElement
implement ISupportInitialize, and when
the EndInit method of that interface
is called, the IsInitialized property
is set to true, and the Initialized
event is fired.

Loaded Event

The Loaded event fires when an element
is not only initialized, but it is
about to be rendered. The motivation
for the Loaded event is the typical
scenario where you want to do some
initialization in your application at
load-time.

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