Search code examples
c#wpfwindows-phone-8longlistselector

LongListSelector ItemsPresenter not showing items


I'm developing a WP8 app.

I have a LongListSelector that shows items fetched from a web service. When the user reaches the end of the list there must be a "Load more" button at the bottom to inovke the web service and get more items.

The list has a style like this to show the button:

<Style x:Key="DenouncesDistanceList" TargetType="phone:LongListSelector">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="phone:LongListSelector">
                    <ScrollViewer x:Name="ScrollViewer">
                        <StackPanel>
                            <ItemsPresenter />
                            <Button x:Name="LoadMoreToList" Click="LoadMoreToList_Click" >Load moremás</Button>
                        </StackPanel>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

When running the app like this the phone shows the button but never shows the items. If I take out the style property on the LongListSelector declaration the items are shown but on a never ending scroll that repeats the items.

This are the definitions of the LongListSelector (with and without the style property):

<phone:LongListSelector x:Name="LisByDistanceListBox" ItemTemplate="{StaticResource ReportListDataTemplate}" Margin="0,0,-24,0" Background="{x:Null}" ItemsSource="{Binding ReportsByDistance}" Width="480" Height="476" VerticalAlignment="Top" Style="{StaticResource DenouncesDistanceList}" />

<phone:LongListSelector x:Name="LisByDistanceListBox" ItemTemplate="{StaticResource ReportListDataTemplate}" Margin="0,0,-24,0" Background="{x:Null}" ItemsSource="{Binding ReportsByDistance}" Width="480" Height="476" VerticalAlignment="Top" />

Before using the LongListSelector I was using a ListBox with the same Style and the same ItemTemplate and everything worked well until too many items were loaded forcing the app to rise an OutOfMemoryException.

Any help?


Solution

  • Never mind, solved this using the LongListSelector.ListFooter like stated on this answer: https://stackoverflow.com/a/13432573/2686243