locked
[UWP]How to Maintain Position of ScrollViewer RRS feed

  • Question

  • Hi, i m developing UWP App and using listview in it. I m using json parsing technique to bind data to listView.

              protected async override void OnNavigatedTo(NavigationEventArgs e)
            {

                HttpClient http = new HttpClient();
                HttpResponseMessage response = await http.GetAsync("http://mmmm.com/json.php");
                response.EnsureSuccessStatusCode();
                string resultJSON = string.Empty;
                resultJSON = await response.Content.ReadAsStringAsync();
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(resultJSON));
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<NameObjects>));
                this.Names.Clear();
                

                foreach (var item in (List<NameObjects>)serializer.ReadObject(ms))
                {
                    
                    this.Names.Add(item);
                }
                this.DataList.ItemsSource = this.Names;


            }

    ............   

     The Data is successfully bind to the listView. I have more then 500 rows in the listView. Whenever the user click the particular row it will navigate to the second page where it shows the details of the selected row. 

    Now the problem is that whenever user navigate back to listView Page the ListView Data Refreshes. and the position of ScrollVier goes back to top. 

    I want two thing one is that it just load the the data once when user open the app not every time whenever user goes to the listview Page.

    Second is that it will maintain the position of scrollviwer e;g the user clicked the 250th row and then it navigate to second page and when it come back to listview the position of the listview ScrollViewer be the same at the 250th not the 1st row.

    For me the scrollView Position moved to top i want where user left last like at 250th row.

    Thanks


    Osama Usmani


    • Edited by Barry Wang Wednesday, July 6, 2016 6:32 AM title tag
    Monday, July 4, 2016 11:48 PM

Answers

  • see https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlListView and

    Restore Scroll Position Sample: Demonstrates how to restore a list's scrollviewer position when a user navigates away and back from a page. Implements the ListViewPersistenceHelper API


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Proposed as answer by Barry Wang Wednesday, July 6, 2016 6:39 AM
    • Marked as answer by Barry Wang Wednesday, July 13, 2016 10:10 AM
    Tuesday, July 5, 2016 8:23 AM

All replies

  • Use the ListView's ScrollIntoView method on the item the user clicked on.
    Tuesday, July 5, 2016 6:52 AM
  • see https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlListView and

    Restore Scroll Position Sample: Demonstrates how to restore a list's scrollviewer position when a user navigates away and back from a page. Implements the ListViewPersistenceHelper API


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Proposed as answer by Barry Wang Wednesday, July 6, 2016 6:39 AM
    • Marked as answer by Barry Wang Wednesday, July 13, 2016 10:10 AM
    Tuesday, July 5, 2016 8:23 AM
  • It doesn't work Build 14393
    Friday, October 21, 2016 11:29 AM