ListboxItem 加载多次
我的列表框项目的故事板上有一个触发器,其中触发器为“已加载”。 似乎每次列表框滚动时,该项目都会收到“Loaded”事件。 我真的只希望故事板在显示列表框项时运行一次。
我假设 Loaded 事件只会被触发一次。
任何帮助都会很棒。
谢谢!
I have a trigger on a storyboard for my listboxitem where the trigger is 'Loaded'.
It appears that every time the listbox scrolls the item gets the 'Loaded' event.
I really only want the storyboard to run once, when the listboxitem gets displayed.
I assumed that the Loaded event would only get triggered once.
Any help would be great.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你是否可以让它只运行一次。 大多数情况下,
ListBox
使用VirtualizingStackPanel
作为其ItemsPanel
。 这会导致仅创建那些可见(或几乎可见)的ListBoxItems
并将其添加到可视化树中。 滚动离开后,可见的项目将被销毁,然后创建新的可见项目。 每次滚动到某个项目时,都会重新创建该项目,因此会触发其Loaded
事件。I'm not sure if you can have it run only once or not. Most times the
ListBox
uses aVirtualizingStackPanel
for itsItemsPanel
. This causes only thoseListBoxItems
that are visible (or nearly visible) to be created and added to the visual tree. Once you scroll away, the items that were visible are destroyed, and then the newly visible items are created. Each time that you scroll to an item, it would be recreated, and thus itsLoaded
event will fire.您可以尝试为列表框设置 VirtualizingStackPanel.IsVirtualizing="False" ,这样就可以了。 请注意,这会消耗更多资源,因为无论您是否在列表中看到项目,它们都将始终存在。 如果里面没有太多物品的话应该不成问题。
You could try setting VirtualizingStackPanel.IsVirtualizing="False" for your listbox, that should do it. Be aware that this consumes more resources since items will always be there no matter if you see them in the list or not. Shouldn't be a problem though if you don't have too many items in it.