ScrollViewer不会对Grid.Row位置做出反应

时间:2012-08-20 21:29:54

标签: c# .net xaml windows-8 visual-studio-2012

我的StackPanel和ScrollViewer似乎不会在Grid.Row位置结束。我正在制作一个Metro应用程序,因此网格必须是动态的,以及所有元素。

代码:

<Grid Background="#FFE4E4E4">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.5*"/>
            <ColumnDefinition Width="0.5*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.5*"/>
            <RowDefinition Height="0.5*"/>
        </Grid.RowDefinitions>

        <!--News/Leaderboard Feed-->
        <StackPanel Grid.Column="0" Grid.Row="0">

        </StackPanel>

        <!--Marketplace Feed-->
        <StackPanel Grid.Column="0" Grid.Row="1">

        </StackPanel>

        <!--Detailed Marketplace Account-->
        <StackPanel Grid.Column="1" Grid.Row="1">

        </StackPanel>


        <!--Marketplace View-->
        <StackPanel Grid.Column="1" Grid.Row="0" VerticalAlignment="Top">
            <ScrollViewer VerticalAlignment="Top">
                <!--Allows scrolling-->

                <GridView x:Name="MarketplaceFeed" ItemsSource="{Binding StockList}" ItemTemplate="{StaticResource MarketplaceFeedTemplate}" VerticalAlignment="Top">
                    <!--Displays the stock markets the user is interested in.-->
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                </GridView>


            </ScrollViewer>
        </StackPanel>

    </Grid>

1 个答案:

答案 0 :(得分:1)

您应该将 ScrollViewer 放在外面。这将自动适应网格,其中的任何内容都将获得滚动处理。

   <!--Marketplace View-->
    <ScrollViewer VerticalAlignment="Top" Grid.Column="1" Grid.Row="0">
        <StackPanel VerticalAlignment="Top">
            <!-- other content -->
        </StackPanel>
    </ScrollViewer>