简体   繁体   English

在Windows Phone 8.1 XAML中使用WrapGrid的ListView的奇怪行为

[英]Strange behavior of ListView with WrapGrid in Windows Phone 8.1 XAML

I have a Windows Phone 8.1 XAML app with a ListView nad WrapGrid as its ItemsPanel to display items in two columns 我有一个带有ListView nad WrapGrid的Windows Phone 8.1 XAML应用程序作为其WrapGrid来显示两列中的项目

<ListView x:Name="ListV" ItemClick="ListV_ItemClick" IsItemClickEnabled="True">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" ItemWidth="160" ItemHeight="280" MaximumRowsOrColumns="2" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Background="Red" Margin="12" Width="100" Height="100"></Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

The cache mode of the page is set to NavigationCacheMode.Required . 页面的缓存模式设置为NavigationCacheMode.Required

I scoll in the list, tap an item and navigate to another screen. 我在列表中搜索,点击一个项目并导航到另一个屏幕。 When I navigate back to the page with the ListView , the ListView remebers the scoll position ( NavigationCacheMode.Required ) but gets "broken", when I tap on items, they just jump strangely. 当我使用ListView导航回页面时, ListView记住scoll位置( NavigationCacheMode.Required ),但会“破坏”,当我点击项目时,他们只是奇怪地跳起来。

Here is a complete simple solution to reproduce the problem: https://dl.dropboxusercontent.com/u/73642/listview.zip . 以下是重现问题的完整简单解决方案: https//dl.dropboxusercontent.com/u/73642/listview.zip

Here is a video showing the problem: https://dl.dropboxusercontent.com/u/73642/listview.wmv 这是一个显示问题的视频: https//dl.dropboxusercontent.com/u/73642/listview.wmv

Anyone else experienced this? 有人经历过这个吗? Is there a way around this issue? 有没有解决这个问题的方法?

One workaround I've found is to wrap the ListView in a ScrollViewer . 我发现一个解决方法是将ListView包装在ScrollViewer Here's a style for vertical scroll viewer: 这是垂直滚动查看器的样式:

<Style x:Key="VerticalScrollViewerStyle" TargetType="ScrollViewer">
    <Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
    <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled" />
    <Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
</Style>

And then you wrap the ListView like this: 然后你像这样包装ListView

<ScrollViewer Style="{StaticResource VerticalScrollViewerStyle}">
    <ListView ...>
        ...
    </ListView>
</ScrollViewer>

This way the ListView 's internal ScrollViewer is not used, and this seems to solve your problem. 这样就不会使用ListView的内部ScrollViewer ,这似乎可以解决您的问题。 Now, there might be some issues with some features of the ListView that depend on the internal ScrollViewer to be used (eg incremental loading). 现在, ListView某些功能可能存在一些问题,这些功能依赖于要使用的内部ScrollViewer (例如增量加载)。 You'll test it and you'll see if what you need works. 你将测试它,你会看到你需要什么工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM