如何在Microsoft Weather应用程序中获得水平滚动?

时间:2017-03-09 04:18:03

标签: xaml uwp

在Windows UWP Microsoft天气应用程序的移动版本中,有一个滚动查看器可以垂直向下滚动页面。

然而,在页面中,有一个可以水平滚动的每日预测。我试图在我的页面上的垂直滚动查看器中使用滚动查看器,但是永远无法在水平滚动查看器中获取滚动内容。

我拥有的是这样的东西

<Page ...>

<Grid >

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>


    <!--EntranceNavigationTransitionInfo.IsTargetElement="True"-->
    <ScrollViewer  Grid.Row="1"  ScrollViewer.VerticalScrollMode="Enabled"  HorizontalAlignment="Stretch"   VerticalAlignment="Stretch" ViewChanged="ScrollViewer_ViewChanged"  >

        <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center"  Margin="15,0,15,0" >



            <Grid HorizontalAlignment="Center" Padding="0,0,0,20">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Vertical" Grid.Column="0">

                </StackPanel>
            </Grid>



            <Grid HorizontalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="Auto" ></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" Orientation="Vertical" Padding="0,0,0,0" Margin="0,0,15,0">


                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Vertical">


                </StackPanel>
            </Grid>

            <RichTextBlock Foreground="White"  Margin="0,20,0,0"   VerticalAlignment="Bottom">

            </RichTextBlock>

            <ScrollViewer Margin="0,20,0,0" HorizontalScrollMode="Enabled" HorizontalAlignment="Stretch" VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Disabled">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">

                    <!--In here i have horizontal row of items that I want the user to scroll horizontally to view them like in the MS Weather app -->

                </StackPanel>
            </ScrollViewer>

        </StackPanel>

    </ScrollViewer>
</Grid>

1 个答案:

答案 0 :(得分:1)

我建议您添加HorizontalScrollBarVisibility="Visible"。这可能是因为Scrollview内有Scrollview,那里会有一个错误。它应该是这样的:

<ScrollViewer Margin="0,20,0,0" HorizontalScrollMode="Enabled" HorizontalAlignment="Stretch" VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Visible">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">

                    <!--In here i have horizontal row of items that I want the user to scroll horizontally to view them like in the MS Weather app -->

                </StackPanel>
            </ScrollViewer>

希望它有所帮助!