vjamit
vjamit

Reputation: 195

is there any limit for items in a listbox for windows phone 8?

i have a listbox with around 150 items in it. the problem is that it is not taking any events. other listboxes have less than 90 items and they are working fine.

is there any limit or something which is preventing event handeling??

<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>

Upvotes: 1

Views: 591

Answers (1)

George Nikolaides
George Nikolaides

Reputation: 1386

vjamit please consider using LongListSelector for Windows Phone 8 applications and not the old ListBox.

I have tested LLS with more than 5k items and it loads and plays just fine.

Also there is no need at all to wrap LLS in a ScrollViewer. Check below example:

<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>

Let me know if the above works.

EDITED:

Try applying the following changes on the ScrollViewer: HorizontalScrollBarVisibility="Disabled". Tested with 500+ and it works. Seems like a "bug".

Upvotes: 1

Related Questions