I know by editing the ListBox‘s default style like this, I can have a Button at the very end of the ListBox.
<ScrollViewer x:Name="ScrollViewer" ...>
<StackPanel>
<ItemsPresenter />
<Button />
</StackPanel>
</ScrollViewer>
However, doing this will break the ListBox‘s Virtualization and the rendering time becomes really long.
All I can think of is,
- Create a dummy item and add it to the end of my item collection in
the viewmodel, and have aVisibilityproperty in the dummy object called ButtonGridVisibility and set it toVisibility.Visible. - In my
ListBox‘sItemTemplate, have twoGrids. One displays
the normal item layout, the other displays the Load MoreButton.
Then toggle theirVisibilitybased on ButtonGridVisibility property.
This might work but I just wonder if there is any easier/better way?
I know this is an old post but in case some people stumble upon this:
There is a LongListSelector control available out of the box in WP8 or as part of the Windows Phone Toolkit for WP7 which supports this scenario quite neatly. If you want to add specific content after the last item (or before the first item), you can simply set the ListFooter or ListHeader of the control. You can put any content inside and this content will be scrolled accordingly, together with the rest of the items.
So for WP7 this would look like this:
where
toolkitisxmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"