locked
How to get scroll position of our listview? RRS feed

  • Question

  • Hi,

    I have a listview control in my mainpage. When user clicks any of the listview item, it navigates to another page and then it will navigate back to its original mainpage.

    I need to ensure following scenario :

    When user clicks the listview item, the scroll position(pixel) of the clicked item in that UI is maintained and once the user comes back again to that page after navigation, the same scroll position should be loaded.

    There is a property called ListView.ScrollPosition available in JavaScript which gets or sets the distance ,in pixels, between the first item in the list and current viewable area.

    But, there is no similar control available for C# to track the same. There is a property available called ListView.ScrollIntoView but it scrolls to the object(listview item), that means the exact scroll position is not maintained here.

    Is there any way to maintain Scroll position in C#?



    Monday, June 25, 2012 12:19 PM

Answers

  • This post shows how to access the scrollbars of e.g. a GridView:

    How can I get the position of scroll bar in GridView?        

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/8d677bd6-f7cd-4099-b9ca-e398b749c92c

    From that scrollbar we can get its HorizontalOffset and its VerticalOffset, and set it with ScrollToHorizontalOffset and ScrollToVerticalOffset.

    In any case, it may be enough for you by enabling NavigationCacheMode in your page, so the status of the page is mantained when you navigate to another page and back.

    <Page
        x:Class="MyApp.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyApp"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        NavigationCacheMode="Enabled">

    --------------------------------------------------------------------------------

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

    Monday, June 25, 2012 3:04 PM
    Moderator

All replies

  • This post shows how to access the scrollbars of e.g. a GridView:

    How can I get the position of scroll bar in GridView?        

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/8d677bd6-f7cd-4099-b9ca-e398b749c92c

    From that scrollbar we can get its HorizontalOffset and its VerticalOffset, and set it with ScrollToHorizontalOffset and ScrollToVerticalOffset.

    In any case, it may be enough for you by enabling NavigationCacheMode in your page, so the status of the page is mantained when you navigate to another page and back.

    <Page
        x:Class="MyApp.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyApp"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        NavigationCacheMode="Enabled">

    --------------------------------------------------------------------------------

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

    Monday, June 25, 2012 3:04 PM
    Moderator
  • Hi Alejandro,

     Your given snippet is working fine. Thank you so much.

    Regards,

    T G Karthick Babu


    T G Karthick Babu

    Tuesday, June 26, 2012 4:11 AM