Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

silverlight - Add a Load More Button at the end of ListBox without losing Virtualization?

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,

  1. Create a dummy item and add it to the end of my item collection in the viewmodel, and have a Visibility property in the dummy object called ButtonGridVisibility and set it to Visibility.Visible.
  2. In my ListBox's ItemTemplate, have two Grids. One displays the normal item layout, the other displays the Load More Button. Then toggle their Visibility based on ButtonGridVisibility property.

This might work but I just wonder if there is any easier/better way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

<toolkit:LongListSelector ItemsSource="{Binding Items}">
    <toolkit:LongListSelector.ListFooter>
        <Grid>
            <Button />
        </Grid>
    </toolkit:LongListSelector.ListFooter>
</toolkit:LongListSelector>

where toolkit is xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...