简体   繁体   English

为什么GridView中的左上角单元格不滚动?

[英]Why doesn't the top left cell in a GridView scroll?

Problem : I'm using a scrollview INSIDE a gridview. 问题:我在一个gridview中使用了一个滚动视图。 The problem is that the top-left cell never scrolls. 问题是左上角的单元格从不滚动。

I've tried all the other cells in many different combinations and it is only the top left which is unscrollable. 我已经尝试了许多不同组合中的所有其他单元格,只有左上角是不可滚动的。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DigitalMenu"
             x:Class="DigitalMenu.MainPage">

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

        <!-- TOP LEFT : This will NOT SCROLL :(-->
        <ScrollView Grid.Row="0" Grid.Column="0">
            <StackLayout>
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
            </StackLayout>
        </ScrollView>

        <!-- TOP RIGHT This will scroll-->
        <ScrollView Grid.Row="0" Grid.Column="1">
            <StackLayout>
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
            </StackLayout>
        </ScrollView>

        <!-- BOTTOM LEFT This will scroll-->
        <ScrollView Grid.Row="1" Grid.Column="0">
            <StackLayout>
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
            </StackLayout>
        </ScrollView>

        <!-- BOTTOM RIGHT This will scroll-->
        <ScrollView Grid.Row="1" Grid.Column="1">
            <StackLayout>
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
                <Button Text="Something" />
            </StackLayout>
        </ScrollView>

        <ListView>

        </ListView>
    </Grid>

</ContentPage>

Your left top cell can't be scrolled because you placed an empty list view in that space. 您的左上方单元格无法滚动,因为您在该空间中放置了一个空列表视图。 It will overlap your original scroll view content so that you feel like it was stuck. 它将与原始滚动视图内容重叠,以便您感觉它被卡住了。 At the bottom of your code you wrote like: 在代码的底部你写的像:

<Grid>
    ...
    <ListView>
    </ListView>
</Grid>

If you didn't explicitly set its row and column it will be 0. Grid will stretch all of its children to the whole space due to Grid's feature. 如果你没有明确地设置它的行和列,那么它将为0.由于Grid的功能,Grid将把它的所有子节点扩展到整个空间。 And the control you set later will be in the topper hierarchy. 您稍后设置的控件将位于顶层层次结构中。

At last, an empty list view prevents you from touching the scroll view. 最后,空列表视图会阻止您触摸滚动视图。 Your first cell can be scrolled if you remove that list view. 如果删除该列表视图,则可以滚动第一个单元格。

After opening a beer I had the brilliant idea of creating a new GridView and just moving the ScrollView elements from the former GridView to the latter GridView and for some reason that just fixed the problem by itself. 打开啤酒之后,我有了创建新GridView的好主意,只是将ScrollView元素从前一个GridView移动到后一个GridView,并且出于某种原因,它本身就解决了问题。 I still don't know why this happened in the first place 我仍然不知道为什么会发生这种情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM