Answered by:
Supress auto scroll when content size changes in ScrollViewer

Question
-
I've placed a gridview inside of a HubSection (who's parent is the Hub's ScrollViewer).
- When the scroll bar's to the left, it stays in place after I add additional items to the gridview.
- If I scroll more than 50%, and then add items, the scroll position is adjusted to show the newly added items.
- Likewise, if I scroll to the end, the scrollbar 'sticks' to the end when items are added.
Is there anyway to disable this behavior completely and just have the scrollbar remain in place (just as it does when I'm scrolled to the left), without using ScrollToHorizontalOffset to manually set the scroll position after items are added?
Test code below:
<Page x:Class="App2.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App2" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Hub Header="Hub"> <HubSection Header="HubSection 0" Width="686"> <DataTemplate> <Grid/> </DataTemplate> </HubSection> <HubSection x:Name="hubSection1" Header="HubSection 1"> <DataTemplate> <Grid> <GridView x:Name="gridView" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Loaded="gridView_Loaded" > <GridView.Resources> <DataTemplate x:Key="GridViewItemTemplate"> <Grid Width="100"> <TextBlock HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding}" VerticalAlignment="Top" FontSize="72"/> </Grid> </DataTemplate> </GridView.Resources> <GridView.ItemTemplate> <StaticResource ResourceKey="GridViewItemTemplate"/> </GridView.ItemTemplate> </GridView> </Grid> </DataTemplate> </HubSection> </Hub> <Button Content="Add items" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="180,51,0,0" Height="60" Width="308" Click="Button_Click"/> </Grid> </Page>
using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace App2 { public sealed partial class MainPage : Page { private GridView _gridView { get; set; } private int count = 0; public MainPage() { this.InitializeComponent(); } private void gridView_Loaded(object sender, RoutedEventArgs e) { _gridView = (GridView) sender; //initial items for (int i = 0; i < 100; i++) _gridView.Items.Add(count++); } private void Button_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < 100; i++) _gridView.Items.Add(++count); } } }
Thursday, December 26, 2013 7:52 PM
Answers
-
No you cannot. This is the default and expected behavior. Reconsider changing this behavior as you will confuse your customers and they will think this is broken in your app!
Jeff
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, December 27, 2013 4:52 PM
- Marked as answer by Jamles HezModerator Friday, January 3, 2014 5:43 AM
Friday, December 27, 2013 4:52 PMModerator
All replies
-
I will try and build your sample code!
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)Friday, December 27, 2013 4:41 PMModerator -
No you cannot. This is the default and expected behavior. Reconsider changing this behavior as you will confuse your customers and they will think this is broken in your app!
Jeff
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, December 27, 2013 4:52 PM
- Marked as answer by Jamles HezModerator Friday, January 3, 2014 5:43 AM
Friday, December 27, 2013 4:52 PMModerator