Xamarin.Forms。Collectionview 在其内容后添加了很多额外的空白

Анд*_*нов 3 xaml collectionview xamarin xamarin.forms

我希望集合视图的内容后面没有空白区域。

\n

我尝试将按钮放在页脚中,但后来遇到了问题,属性 isenabled = false 没有在我后面的代码中应用到它。\n这是我的 xaml 文件:

\n
<ContentPage.Content>\n    <RefreshView x:DataType="local:QuestionViewModel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">\n        <ScrollView>\n            <StackLayout>\n                <views:MyTextView LaTeX="{Binding Formulation}" HorizontalOptions="Center" Margin="15, 10, 15, 0"/>\n                <!--<RefreshView x:DataType="local:QuestionViewModel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">-->\n                    <CollectionView\n                        ItemsSource="{Binding Answers, Mode=TwoWay}"\n                        SelectedItems="{Binding SelectedAnswers, Mode=TwoWay}"\n                        SelectionMode="Multiple"\n                        x:Name="collectionView"\n                        SelectionChanged="collectionView_SelectionChanged"\n                        >\n                        <CollectionView.ItemsLayout>\n                            <LinearItemsLayout Orientation="Vertical"/>\n                        </CollectionView.ItemsLayout>\n                    <CollectionView.ItemTemplate>\n                        <DataTemplate x:DataType="model:Answer">\n                            <StackLayout Padding="10">\n                                <VisualStateManager.VisualStateGroups>\n                                    <VisualStateGroup Name="CommonStates">\n                                        <VisualState Name="Normal">\n                                            <VisualState.Setters>\n                                                <Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{Binding AnswerColor}"/>\n                                            </VisualState.Setters>\n                                        </VisualState>\n                                        <VisualState Name="Selected">\n                                            <VisualState.Setters>\n                                                <Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{DynamicResource MainColor}"/>\n                                                <Setter TargetName="label" Property="views:MyTextView.TextColor" Value="White"/>\n                                            </VisualState.Setters>\n                                        </VisualState>\n                                    </VisualStateGroup>\n                                </VisualStateManager.VisualStateGroups>\n                                <Frame CornerRadius="10" HasShadow="True" x:Name="frame" BackgroundColor="{Binding AnswerColor}">\n                                    <views:MyTextView x:Name="label" LaTeX="{Binding Content}" />\n                                </Frame>\n                            </StackLayout>\n                        </DataTemplate>\n                    </CollectionView.ItemTemplate>\n                </CollectionView>\n                <!--</RefreshView>-->\n                <StackLayout>\n                    <Label x:Name="conditionLabel" TextColor="{DynamicResource AnswerColor}"/>\n                    <Button x:Name="checkButton" Text="\xd0\x9f\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xb8\xd1\x82\xd1\x8c \xd0\xbe\xd1\x82\xd0\xb2\xd0\xb5\xd1\x82\xd1\x8b" CornerRadius="10" Margin="10"\n                                Command="{Binding CheckAnswersCommand}"/>\n                </StackLayout>\n            </StackLayout>\n        </ScrollView>\n    </RefreshView>\n</ContentPage.Content>\n
Run Code Online (Sandbox Code Playgroud)\n

结果:\n屏幕的 1 部分\n屏幕的 2 部分

\n

小智 7

您不应该按照官方文档中的描述在 Scrollview 中使用 Listview/Collection View。

滚动视图中有一个列表视图的替代方案。看下面的代码:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ScrollViewDemos"
             x:Class="ScrollViewDemos.Views.ColorListPage"
             Title="ScrollView demo">
    <ScrollView>
        <StackLayout BindableLayout.ItemsSource="{x:Static local:NamedColor.All}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <StackLayout Orientation="Horizontal">
                        <BoxView Color="{Binding Color}"
                                 HeightRequest="32"
                                 WidthRequest="32"
                                 VerticalOptions="Center" />
                        <Label Text="{Binding FriendlyName}"
                               FontSize="24"
                               VerticalOptions="Center" />
                    </StackLayout>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </ScrollView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

请关注文档以获得更多支持: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scrollview