JumpyStackOverflow
JumpyStackOverflow

Reputation: 720

How to enable lefto-right scrolling of GridView in Windows Phone 8.1 WinRT?

I am trying to change the orientation of GridView from the default up-down to left-right. Only I cannot get manual scolling to function even though calling ScrollIntoView from code behind works just fine. Here are details for my test project.

1) File >> New Project >> Hub App (Windows Phone)

2) HubPage.xaml (Hub control removed and replaced with just a GridView)

    <Grid x:Name="LayoutRoot" DataContext="{Binding Groups[5]}">
    <GridView x:Name="GridView1" Margin="0,9.5,0,0"
              ItemsSource="{Binding Items}"
              SelectionMode="None"
              IsItemClickEnabled="True"
              ItemClick="ItemView_ItemClick"
              ScrollViewer.VerticalScrollBarVisibility="Visible"  
              ScrollViewer.HorizontalScrollBarVisibility="Visible">

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <ItemsWrapGrid  Orientation="Vertical"  
                                ScrollViewer.HorizontalScrollBarVisibility="Visible" 
                                ScrollViewer.VerticalScrollBarVisibility="Visible"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>

        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid Margin="0,0,9.5,9.5" 
                      Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
                    <Image Source="{Binding ImagePath}" 
                           Stretch="UniformToFill" 
                           AutomationProperties.Name="{Binding Title}" 
                           Height="200" 
                           Width="200"/>
                    <TextBlock Text="{Binding Title}" 
                               VerticalAlignment="Bottom" 
                               Margin="9.5,0,0,6.5" 
                               Style="{ThemeResource BaseTextBlockStyle}"/>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>

    </GridView>
</Grid>

3) HubPage.xaml.vb (only change in this click handler)

Private Sub ItemView_ItemClick(sender As Object, e As ItemClickEventArgs)
    GridView1.ScrollIntoView(GridView1.Items.Last)
End Sub

What am I missing here?

Upvotes: 3

Views: 1525

Answers (1)

Igor Ralic
Igor Ralic

Reputation: 15006

GridView needs to have it enabled. So, in the GridView, you also need to set the HorizontalScrollMode property.

<GridView x:Name="GridView1" Margin="0,9.5,0,0"
          ItemsSource="{Binding Items}"
          SelectionMode="None"
          IsItemClickEnabled="True"
          ItemClick="ItemView_ItemClick"
          ScrollViewer.VerticalScrollBarVisibility="Visible"  
          ScrollViewer.HorizontalScrollBarVisibility="Visible"
          ScrollViewer.HorizontalScrollMode="Auto">

....

</GridView>

Upvotes: 5

Related Questions