Building Apps for Windows Phone 8.1: (04) Lists and Lists Items in Windows Runtime Apps

Play Building Apps for Windows Phone 8.1: (04) Lists and Lists Items in Windows Runtime Apps

The Discussion

  • User profile image

    Could you please tell me how to save and restore the listview "scroll position" when no item is selected? Is there a way to access the items that are currently "visible"?

  • User profile image


    It's a little roundabout, but you can use the ItemsPanel to find the index of first visible item in the list. From there you can get the container for that item and from that container you can get the item. You can use that item to scroll to the correct position.

    var isp = (ItemsStackPanel)SampleListView.ItemsPanelRoot;
    int firstVisibleItem = isp.FirstVisibleIndex;
    var container = SampleListView.ContainerFromIndex(firstVisibleItem);
    var item = (MyObject)SampleListView.ItemFromContainer(container);

  • User profile image

    Great video! I am developing an app where I am trying to implement pull to refresh functionality using list view. I posted the question on windows Phone forums but haven't received a solution. Can anyone please help me with that.

  • User profile image

    Hello, can you please help me with a better solution to search a Listview OR Gridview. During the search I would like to hide the non matches, and show the matches. I currently have a solution, but its really slow once the list start getting really big.

  • User profile image

    @matthiasS: Thank you. I will try this as soon as I'm finished translating my WP8.0 code to WP8.1.

  • User profile image

    Took me a while to figure out the VB translation of the linq query. Maybe posting it here will save others some time:

    Dim groupedItems As New List(Of KeyedList(Of String, SampleItem))
    Dim gruuppi = _
                From item In items
                Order By item.TargetGroup, item.Title
                Group By item.TargetGroup Into itemsByCompany = Group
                Select New KeyedList(Of String, SampleItem)(TargetGroup, itemsByCompany)
    groupedItems = gruuppi.ToList
    Return groupedItems

    Oh and the source code for these videos can be found at Andy Wigley's OneDrive account [].

  • User profile image

    How come the bindings to a CollectionViewSource work fine in run time but not in design time?

    To accomplish "groupedlist" functionality in WP8.1 must I bind to a CollectionViewSource or are there other options with design time support? Surely Microsoft does not expect us to start coding user interfaces blind like one used to before VISUAL studio?

  • User profile image


    What I normally do for design-time visuals is create a set of static data that I plan to use at design time and use the "d" designation. Example:

    First add the d xml namespace:


    Then set d to be ignored on runtime:


    Then set your design time DataContext in the XAML with the d prefix

    d:DataContext="{Binding MyDesignViewModel}"

    With that, you can use a simple list of lists for design purposes and you won't have to use the CollectionViewSource.

  • User profile image

    @dubem: Without knowing the details of your solution, my guess is that you would actually want to keep all of your items in a "AllItems" collection in your ViewModel and bind your ListView or GridView to a "SearchResultsItems" for the ItemsSource. You could then add or remove the items from that second ObservableCollection in your ViewModel rather than try to do the add-remove within the control.

  • User profile image

    , matthiasS wrote

    -- you can use a simple list of lists for design purposes and you won't have to use the CollectionViewSource.

    This is good news. I had the impression that CVS was a must with "groupedlists".

    Currently I am working on a simple-test-app just to get started. Here is the working xaml and code behind from VS2012-WP8.0-app plus what I have for VS2013-WP8.1-WinRT so far:

    The 8.1 app does not work even in runtime. What changes are required to my xaml or code behind as migrating my simple-test-app from 8.0 to 8.1 WinRT?

  • User profile image

    Finally managed to get my grouped list sample working both design and run time.

    Here is the final code:


  • User profile image


    I downloaded the sample codes and tested them in my Lumia 525 running developer Preview 8.1

    When I run the grouped list view template, the group headed keeps bouncing up and down.

    Is it just me or is it because of the developer preview version of the OS?

    And also I have the feeling that lists in Silverlight apps run much smoother and render much faster.

  • User profile image

    I want to implement panning and zooming in my app,where a user can pan and a zoom a video .How can i do that ?

  • User profile image

    where can I get the project example of this section?

  • User profile image


    My recommendation for panning and zooming a video would be to either
    1) Put the video into a Scrollviewer and see if that does it

    2) Use the Player Framework media player ( an enormously flexible media player that works on all recent versions of Windows and Windows Phone.

  • User profile image
  • User profile image


    I got some problem to implement this grouped listview for json file in local folder
    any reference how to use this method for non static data?

  • User profile image

    Great video!

    I have been looking a way to change a background of the selected item in ListView. So, when I press the item, the background of that item will change. It sounds simple, but I am confused which to change in the default ItemContainerStyle.

    I presumed the state that I should look into is "pressed". However, when I changed the background, it will only change the background of the tilt animation. How can I remove away the tilt animation and simply change the background of the selected item. FYI, I also set the background of each item in the DataTemplate; well, just in case it would affect the treatment.

    Thank you.

  • User profile image

    @Sasa: Because of the complex nature of the ListView, it uses a ListViewItemPresenter control in the ItemContainerStyle. This controlt has a LOT of brushes attached to it. If you change the SelectedBackground and SelectedPointerOverBackground, that should change the background of the item when it is selected.

    I don't currently see an easy way to remove the tilt, sorry. 

  • User profile image

    Hello everyone!

    I'm a student, I want to create an app that is music player, non-benefit purpose.

    But I can not afford. Guys can give me some help?

    "I want to get all file .mp3 extensions and show it on listview or gridview"

    Thanks guys!

  • User profile image

    how do I get index of item that click in listview(I don not khown whay is allway=-1) my listview is set selectionmode=single


  • User profile image

    I just want a list with simple text in it. Please explain EXACTLY how to do that. You explain that as if I knew how to generate a binding and stuff...I DON'T KNOW * about it.

    That line:
    ItemsSource="{Binding Source={StaticResource Items}}"

    is NOT in my ListView when I drag it into my app.

    I don't know how to generate a template or what to do here, please explain that too.


  • User profile image
    Marios Katsis

    Very nice video!
    Is there a way to make the Items of the Grouped List View to be scrolled horizontally?

  • User profile image

    Any time you tell me to design my UI by opening up a TEXT EDITOR to enter XAML by hand you have failed me.

    This whole series of videos in unique in that you can spend 30 minutes watching hoping to learn something, but don't really learn anything because you guys just apply things you've already created.



  • User profile image

    Hello Everyone,

    I want to save some client data with its respective image. For storing image, I've converted bitmap image into byte array and stored that array in database but while displaying all records, I want to display respective image for particular client in list view.

    I've checked example but in that images are coming from folder and not from database. 

    Please share if anyone has example.



  • User profile image
    san pandit

    Thanks for the tutorial its really great video for listview.
    Please tell me how i can make a expandable listview.

    San K

  • User profile image


    Hi, I cannot download the sample code for these projects,could you please send me a mail of that.


Add Your 2 Cents