如何滚动网格Windows Phone 8.1

时间:2015-02-25 09:37:11

标签: xaml windows-phone-8.1

我有一个设置页面,在4个不同的堆栈面板中有几个Textbox组件。 每个面板都在Grid组件中:

<Grid>

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

    <StackPanel Margin="10,0,0,30" Grid.Row="0">...

    <StackPanel Name="stackSettings" Grid.Row="1">...

    <StackPanel Name="stackCustomSettings" Grid.Row="2">...

    <StackPanel Name="stackSaveSettings" Grid.Row="3">...

</Grid>

如何修改我的xaml以使网格垂直滚动?

2 个答案:

答案 0 :(得分:1)

以下代码对我有用:

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

            <StackPanel Margin="10,0,0,30" Grid.Row="0">...

            <StackPanel Name="stackSettings" Grid.Row="1">...

            <StackPanel Name="stackCustomSettings" Grid.Row="2">...

            <StackPanel Name="stackSaveSettings" Grid.Row="3">...
        </Grid>
    </ScrollViewer>
</Page>

你的父元素是什么? StackPanel?

答案 1 :(得分:0)

Fisrt of all,这段代码:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <!-- Your content -->
</Grid>

等于:

<StackPanel>
    <!-- Your content -->
</StackPanel>

因为每一行的高度都设置为Auto,这意味着整个Grid将与其内容一样高。如果您希望它可滚动,只需将其放在ScrollViewer内。但是,ScrollViewer不能位于StackPanelGrid内,行高设置为Auto,因为它不会滚动。

工作示例:

<Page>
    <ScrollViewer>
        <StackPanel>
            <!--Place your controls here-->
        </StackPanel>
    </ScrollViewer>
</Page>