gpt4 book ai didi

c# - UWP - FlipView - 需要 FlipView 才能仅加载单个项目内容

转载 作者:行者123 更新时间:2023-11-30 17:34:48 24 4
gpt4 key购买 nike

上周我一直在努力尝试在 Microsoft News UWP 应用程序中实现 FlipView。

我尝试了以下方法:一个带有 ItemTemplate 的 FlipView 和一个带有我的项目的 ObservableCollection。然而,这导致我的 ObservableCollection 中的所有项目都被预加载,这不是我想要的。

有没有人有任何提示允许我将 FlipView 的这种行为更改为如下所示:仅加载第一个项目,然后当我单击箭头时,加载下一个项目。

提前致谢:)

更新:我可以确认该行为正如 @Sunteen Wu - MSFT 所说。我还尝试使用与 @Martin Zikmund 资助演示的逻辑类似的逻辑,但是,它没有清除上一个项目

我的目标是一次加载 1 个项目。像这样的行为:
1) 我看到 1 项
2) 如果我点击> (next) 箭头:
* 此项已从翻转 View 中卸载
* 加载下一个项目
3) 如果我点击< (previous) 箭头:
* 此项已从翻转 View 中卸载
* 重新加载上一个项目

希望有人能帮忙,我真的很想把那个功能给我的用户^^。

最佳答案

However this caused the whole lot of items within my ObservableCollection to be pre-loaded

FlipView控件的 ItemsPanelTemplate 包含 VirtualizingStackPanel .所以FlipView控件默认是支持虚拟化的。调试应用程序时可以查看可视化树,您可能会发现无论绑定(bind)多少项到 FlipView,默认情况下它只会加载三个 FlipViewItem

enter image description here

所以在我看来,FlipView 不会预加载您的 ObservableCollection 的所有项目,默认情况下它可能会加载前一个、当前的和下一个一,除非您将 ItemPanel 更改为不支持虚拟化的 StackPanel

 <FlipView x:Name="flipView1" Width="480" Height="270" 
BorderBrush="Black" BorderThickness="1">
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
<FlipView.ItemTemplate>
...
</FlipView.ItemTemplate>
</FlipView>

Only the first item is loaded, then when I click the arrow, the next item gets loaded.

作为使用虚拟化的 FlipView,所以我猜您仍然不需要此功能。如果您仍然想要它,您可以尝试将源代码绑定(bind)到实例数据为空的 FlipView,并且每次选择更改时,强制手动加载内容。为此,您可以引用此 similar thread @Martin Zikmund 提供了一个 demo用于单次加载。

此外,根据 Do's and don'ts FlipView 备注:

Avoid using a flip view control for larger collections, as the repetitive motion of flipping through each item can be tedious.

如果您确实有更大的集合用于绑定(bind),请避免使用翻转 View ,而应考虑使用 ListView 或 GridView 。

关于c# - UWP - FlipView - 需要 FlipView 才能仅加载单个项目内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com