在xamarin.forms列表视图中使用滚动

时间:2017-09-18 22:02:11

标签: xaml xamarin.forms.listview

我在listview中返回了大约20行数据,它只显示了12行。 如何在下面的列表视图中引入滚动条。我试着在它周围放一个滚动视图,但没有运气。

     <StackLayout Grid.Column="1" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0" Spacing="0">
                            <SearchBar x:Name="searchBar" Placeholder="Search" SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}"/>
                            <StackLayout VerticalOptions="FillAndExpand">
                                <StackLayout VerticalOptions="FillAndExpand" Padding="1" BackgroundColor="Black">
                                    <ListView x:Name="dataList"  BackgroundColor="White">
                                        <ListView.ItemTemplate>
                                            <DataTemplate>
                                                <ViewCell>
                                                    <Label FontSize="20" VerticalOptions="CenterAndExpand" TextColor="Black" Text="{Binding HeadLines}"></Label>
                                                </ViewCell>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                    </ListView>
                                </StackLayout>
                            </StackLayout>
                        </StackLayout>

1 个答案:

答案 0 :(得分:1)

<强>答案

您的XAML结构错误。请查看我的代码,然后尝试一下。希望,它会帮助你。

<强>代码

<Grid VerticalOptions="FillAndExpand">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <SearchBar Grid.Column="0" x:Name="searchBar" Placeholder="Search" SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}" />
    <ListView Grid.Column="2" x:Name="dataList" BackgroundColor="White">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Label FontSize="20" VerticalOptions="CenterAndExpand" TextColor="Black" Text="{Binding HeadLines}">
                    </Label>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</Grid>