locked
Returning to scroll position in a gridview. RRS feed

  • Question

  • I have an app with a customized gridview. After clicking on an element an returning, the gridview's scroll position it reset.

    I've tried to manually reset the position, with this:

    ScrollViewer viewer = FindVisualChild<ScrollViewer>(ItemGridView);
    viewer.ScrollToVerticalOffset(20);

    But, this code only seems to work when I place it in a button event handler.

    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Monday, March 4, 2013 3:12 AM

Answers

  • Are you trying to keep the state of the Scrollviewer , when you redirect to different page and came back again ? If Yes, then Set 

    NavigationCacheMode="Enabled"

    Note: NavigationCacheMode is a property of page. Add it like this:

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


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, March 4, 2013 5:49 AM

All replies

  • Are you trying to keep the state of the Scrollviewer , when you redirect to different page and came back again ? If Yes, then Set 

    NavigationCacheMode="Enabled"

    Note: NavigationCacheMode is a property of page. Add it like this:

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


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, March 4, 2013 5:49 AM
  • Are you trying to keep the state of the Scrollviewer , when you redirect to different page and came back again ? If Yes, then Set 

    NavigationCacheMode="Enabled"

    Note: NavigationCacheMode is a property of page. Add it like this:

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


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    The above is only a solution if your page only ever has the same datacontext so is pretty much useless for all but the most basic of views.

    Run your code asynchronously on the dispatcher with a low priority.

    Window.Current.Dispatcher.RunAsync(() => viewer.ScrollToVerticalOffset(20), CoreDispatcherPriority.Low);


    British Airways Inspiration App & rara music


    • Edited by Flexman Monday, March 4, 2013 10:50 AM
    Monday, March 4, 2013 10:50 AM
  • That was it, all I needed. Thanks.

    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Monday, March 4, 2013 12:10 PM
  • Thanks for your help anyway, even though I had already ran the code through the dispatcher and that still didn't solve the problem.

    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Monday, March 4, 2013 12:11 PM