Gridview not scrolling horizontally in windows pho

2019-04-09 01:44发布

问题:

.Gridview not scrolling horizontally in windows phone app instead it is scrolling vertically.I just copy paste the code of my windows 8.1 app to windows phone 8.1 but it is scrolling vertically.

here is the xaml code:

    <Grid>
    <Grid.Background>
        <ImageBrush ImageSource="Assets/back3.png"></ImageBrush>
    </Grid.Background>

    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="5*"/>
        <RowDefinition Height=".6*"/>

    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="70"/>
        <ColumnDefinition Width="*"/>

    </Grid.ColumnDefinitions>
    <TextBlock Text="Select Comic" Foreground="Black" FontSize="30" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1"></TextBlock>
    <!-- Back button and page title -->
    <GridView x:Name="myGridview"  Grid.Column="1" Grid.Row="1" SelectionChanged="myGridview_SelectionChanged">
        <GridView.ItemTemplate>
            <DataTemplate>
                <StackPanel  Margin="0,0,20,20">
                    <Image Source="{Binding source}"  Width="100" Height="100" Stretch="Fill"></Image>
                </StackPanel>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>


</Grid>

回答1:

Try by putting ItemsPanel,ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"

<GridView Width="400"  ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel  Margin="0,0,20,20">
                <Image Source="{Binding source}"  Width="100" Height="100" Stretch="Fill"></Image>
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

Update

try by changing Itemspanel : WrapGrid Orientation="Vertical" or Orientation="Horizontal"

<GridView Width="400"  ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid Orientation="Vertical"></WrapGrid>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel  Margin="0,0,20,20">
                <Image Source="{Binding source}"  Width="100" Height="100" Stretch="Fill"></Image>
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>