将新项目添加到 WPF ListBox 时的滑动效果

发布于 2024-08-21 10:38:26 字数 222 浏览 8 评论 0原文

我有一个 WPF ListBox 控件,它显示 RSS 提要的项目。我偶尔会检查 RSS 提要的来源以获取新项目。一旦检测到新项目,我将其添加到可观察集合中,该集合立即将新项目添加到列表框显示中。

有没有办法从顶部“滑入”新项目,向下推现有项目?我怎样才能达到这样的效果呢?可以使用 ListBox 来完成吗?或者我是否需要使用自己的容器(例如 StackPanel)并以编程方式对新添加的控件的高度进行动画处理?

I have a WPF ListBox control which displays items of an RSS feed. I occasionally check the source of the RSS feed for new items. Once I detect a new item I add it to the observable collection which immediately adds the new item to the ListBox display.

Is there a way to 'slide in' the new item from the top, pushing down the existing items? How would I achieve such an effect? Can it be done with a ListBox, or do I need to resort to my own container, such as a StackPanel and animate for example the Height of newly added controls programmatically?

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

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

发布评论

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

评论(2

太傻旳人生 2024-08-28 10:38:26

我刚刚发布了这个问题的答案,与您的非常相似。

WPF 如何为组件列表添加动画

I just posted an answer to this question which is very similar to yours.

WPF how to animate a list of components

潦草背影 2024-08-28 10:38:26

可以使用列表框来完成。使用 ItemContainerStyle 设置绑定为您创建的 ListBoxItems 的样式:此样式可以包括动画,例如通过将 Loaded 事件的 EventTrigger 添加到 Style.Triggers 和转换。例如,在触发操作中,您可以对高度进行动画处理,以便项目展开到位,或者如果高度未知,您可以将样式设置为 ScaleTransform,并在触发操作中将该变换的 ScaleY 进行动画处理,从 0 到 1。

It can be done with a ListBox. Use the ItemContainerStyle to style the ListBoxItems that the binding creates for you: this style can include animations, e.g. by adding an EventTrigger for the Loaded event to the Style.Triggers, and transforms. For example, in your trigger action you could animate the Height so the item expands into place, or if the height is unknown you could have your style set a ScaleTransform and in your trigger action animate the ScaleY of that transform from 0 to 1.

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