Gridview不能在Windows Phone 8.1中水平滚动

时间:2014-07-10 13:09:34

标签: winrt-xaml windows-phone-8.1

.Gridview没有在Windows手机应用程序中水平滚动而是垂直滚动。我只是将我的Windows 8.1应用程序的代码复制粘贴到Windows Phone 8.1但它是垂直滚动。

这是xaml代码:

    <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 个答案:

答案 0 :(得分:6)

尝试推杆 ItemsPanelScrollViewer.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>

<强>更新

尝试更改Itemspanel:WrapGrid Orientation =“Vertical”或Orientation =“Horizo​​ntal”

<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>