【问题标题】:is there any limit for items in a listbox for windows phone 8?Windows Phone 8 的列表框中的项目是否有任何限制?
【发布时间】:2013-08-23 07:14:04
【问题描述】:

我有一个包含大约 150 个项目的列表框。问题是它没有参加任何活动。其他列表框的项目少于 90 个,并且工作正常。

是否有任何限制或阻止事件处理的东西??

<ScrollViewer HorizontalAlignment="Left" Height="170" Margin="0,421,0,0" VerticalAlignment="Top" Width="480" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                        <ListBox Name="thirdList" Tap="firstList_SelectionChanged_1" Height="170" ScrollViewer.VerticalScrollBarVisibility="Disabled" >

                            <toolkit:GestureService.GestureListener>
                                <toolkit:GestureListener DragCompleted="GestureListener_DragCompleted"></toolkit:GestureListener>
                            </toolkit:GestureService.GestureListener>

                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Padding" Value="0 0 0 0 " />
                                </Style>
                            </ListBox.ItemContainerStyle>

                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Vertical" Height="170" Width="150" Background="Transparent">
                                        <!--Replace rectangle with image-->
                                        <Image Source="{Binding image}" Stretch="UniformToFill" Margin="0,20" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="140" Width="119"></Image>
                                        <Grid Margin="0,-335,0,0" HorizontalAlignment="Center" Background="Transparent" Height="30">
                                            <TextBlock TextAlignment="Center" Text="{Binding brandName}" HorizontalAlignment="Center" FontSize="15"  TextWrapping="NoWrap" Foreground="#FFAA1F17" />
                                        </Grid>
                                        <StackPanel Width="165" Margin="0,-65,0,0" Background="Transparent">
                                            <Grid HorizontalAlignment="Stretch" Height="55" Background="#FF9B9A9A">
                                                <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent">
                                                    <TextBlock TextAlignment="Center" Text="{Binding productName}" TextWrapping="Wrap" HorizontalAlignment="Center" Foreground="White" FontSize="15" />
                                                    <TextBlock TextAlignment="Center" Text="{Binding price}" TextWrapping="Wrap" HorizontalAlignment="Center"  Foreground="#99FFFFFF" FontSize="15" />
                                                </StackPanel>
                                            </Grid>
                                        </StackPanel>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </ScrollViewer>

【问题讨论】:

  • 我不明白您的代码的问题,但我使用的 Listbox 包含超过 500 个项目。
  • 我尝试将项目减少到 100 以下,并且成功了。

标签: xaml windows-phone-8


【解决方案1】:

vjamit 请考虑将LongListSelector 用于Windows Phone 8 应用程序,而不是旧的ListBox。

我已经用超过 5k 个项目测试了 LLS,它可以正常加载和播放。

此外,根本不需要将 LLS 包装在 ScrollViewer 中。检查以下示例:

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="LLSTemplate">
        <Grid Tap="firstList_SelectionChanged_1">
            <toolkit:GestureService.GestureListener>
                <toolkit:GestureListener DragCompleted="GestureListener_DragCompleted"></toolkit:GestureListener>
            </toolkit:GestureService.GestureListener>

            <StackPanel Orientation="Vertical" Height="170" Width="150" Background="Transparent">
                <!--Replace rectangle with image-->
                <Image Source="{Binding image}" Stretch="UniformToFill" Margin="0,20" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="140" Width="119"></Image>
                <Grid Margin="0,-335,0,0" HorizontalAlignment="Center" Background="Transparent" Height="30">
                    <TextBlock TextAlignment="Center" Text="{Binding brandName}" HorizontalAlignment="Center" FontSize="15"  TextWrapping="NoWrap" Foreground="#FFAA1F17" />
                </Grid>
                <StackPanel Width="165" Margin="0,-65,0,0" Background="Transparent">
                    <Grid HorizontalAlignment="Stretch" Height="55" Background="#FF9B9A9A">
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent">
                            <TextBlock TextAlignment="Center" Text="{Binding productName}" TextWrapping="Wrap" HorizontalAlignment="Center" Foreground="White" FontSize="15" />
                            <TextBlock TextAlignment="Center" Text="{Binding price}" TextWrapping="Wrap" HorizontalAlignment="Center"  Foreground="#99FFFFFF" FontSize="15" />
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </StackPanel>
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>


<!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <phone:LongListSelector x:Name="thirdList" Height="170" ItemTemplate="{StaticResource LLSTemplate}"/>
    </Grid>

如果上述方法有效,请告诉我。

已编辑

尝试在 ScrollViewer 上应用以下更改:HorizontalScrollBarVisibility="Disabled"。用 500+ 测试,它的工作原理。看起来像一个“错误”。

【讨论】:

  • 问题是,我需要水平滚动列表。据我所知并搜索过,LongListSelector 是不可能的。我可以请告诉我。
  • 请检查我所做的编辑......它应该可以工作 - 它对我有用!
  • 试过了..仍然无法正常工作..它的工作原理是这样的:当页面加载时它显示 5 个项目并且点击事件有效,然后加载更多数据。一旦填充了所有数据,既不会调用点击事件处理程序,也不会调用 GestureListener。可能与更新列表框有关。
  • 但所有其他列表框都遵循相同并且工作正常。
  • 在我的示例中,我将列表项加载到 observablecollection 中,然后我将列表框的 itemsource 显式绑定到该集合。尝试使用 500+ 并且该​​行看起来影响了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多