locked
How to add (Load More) button as the last item of a gridview?

    Question

  • Hi All,

             I have a GridView which can grow. So am displaying first 5 items at the beginning. after the 5th item I want a "Load More" button. Upon clicking it, lets say 10 more items gets added to the gridview.

    Now I want that "Load More" button to be displayed after 15th item. I mean "Load More" should always be the last item of the GridView. How to achieve this?

    Any idea is greatly in need.

    Thanks

    Rajesh

    Monday, July 21, 2014 11:06 AM

Answers

  • As Matt says, if you have ungrouped data then take a look at data virtualization to fit everything in at once.

    If you have grouped data (e.g. like the News app) and want to show only the first X items at a time in each group then your "Load more" button makes sense. You can insert a dummy item into your bound data collection for the button and use a DataTemplateSelector to display a load more tile for the dummy item.

    I don't see an existing sample that is exactly this, but the How to disable specified items selection in Listview/Gridview sample demonstrates using a DataTemplateSelector to enable or disable specific items. You can use the same general technique to completely swap out the item template for specific items so you can display either your real data or your dummy item as needed.

    --Rob

    Monday, July 21, 2014 9:28 PM
    Owner

All replies

  • You should be using data virtualization instead.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, July 21, 2014 7:18 PM
    Moderator
  • As Matt says, if you have ungrouped data then take a look at data virtualization to fit everything in at once.

    If you have grouped data (e.g. like the News app) and want to show only the first X items at a time in each group then your "Load more" button makes sense. You can insert a dummy item into your bound data collection for the button and use a DataTemplateSelector to display a load more tile for the dummy item.

    I don't see an existing sample that is exactly this, but the How to disable specified items selection in Listview/Gridview sample demonstrates using a DataTemplateSelector to enable or disable specific items. You can use the same general technique to completely swap out the item template for specific items so you can display either your real data or your dummy item as needed.

    --Rob

    Monday, July 21, 2014 9:28 PM
    Owner