微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决Xamarin.Forms Collectionview 在其内容之后添加了很多额外的空白

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

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

<ContentPage.Content>
    <RefreshView x:DataType="local:Questionviewmodel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy,Mode=TwoWay}">
        <ScrollView>
            <StackLayout>
                <views:MyTextView LaTeX="{Binding Formulation}" HorizontalOptions="Center" Margin="15,10,15,0"/>
                <!--<RefreshView x:DataType="local:Questionviewmodel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy,Mode=TwoWay}">-->
                    <CollectionView
                        ItemsSource="{Binding Answers,Mode=TwoWay}"
                        SelectedItems="{Binding SelectedAnswers,Mode=TwoWay}"
                        SelectionMode="Multiple"
                        x:Name="collectionView"
                        SelectionChanged="collectionView_SelectionChanged"
                        >
                        <CollectionView.ItemsLayout>
                            <LinearItemsLayout Orientation="Vertical"/>
                        </CollectionView.ItemsLayout>
                    <CollectionView.ItemTemplate>
                        <DataTemplate x:DataType="model:Answer">
                            <StackLayout Padding="10">
                                <visualstatemanager.VisualStateGroups>
                                    <VisualStateGroup Name="CommonStates">
                                        <VisualState Name="normal">
                                            <VisualState.Setters>
                                                <Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{Binding AnswerColor}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState Name="Selected">
                                            <VisualState.Setters>
                                                <Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{DynamicResource MainColor}"/>
                                                <Setter TargetName="label" Property="views:MyTextView.TextColor" Value="White"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>
                                </visualstatemanager.VisualStateGroups>
                                <Frame CornerRadius="10" HasShadow="True" x:Name="frame" BackgroundColor="{Binding AnswerColor}">
                                    <views:MyTextView x:Name="label" LaTeX="{Binding Content}" />
                                </Frame>
                            </StackLayout>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
                <!--</RefreshView>-->
                <StackLayout>
                    <Label x:Name="conditionLabel" TextColor="{DynamicResource AnswerColor}"/>
                    <Button x:Name="checkButton" Text="Проверить ответы" CornerRadius="10" Margin="10"
                                Command="{Binding CheckAnswersCommand}"/>
                </StackLayout>
            </StackLayout>
        </ScrollView>
    </RefreshView>
</ContentPage.Content>

结果: 1 part of screen 2 part of screen

解决方法

不幸的是,这是一个已知问题,并且是 open issue

请参阅该线程以了解可能的解决方法。并跟踪修复进度。

底线:您必须手动指定/计算高度。有多种方法可以做到这一点,难度各不相同。线程提到了一些。您需要通过 Google 了解更多详情。

我喜欢的一种快速而肮脏的解决方案是在可接受的情况下将 CollectionView 包装在 Grid 中,然后使用 RowDefinitions 强制为包含 CollectionView 的行提供多少高度,为其他所有内容提供多少高度。类似的东西:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*" />
        <RowDefinition Height="2*" />
    </Grid.RowDefinitions>

    <CollectionView Grid.Row="0" ...>
        ...
    </CollectionView>

    <StackLayout Grid.Row = "1" ...>
        ... everything that is below the CV ...
    </StackLayout>
 </Grid>

这会将第 0 行(包含 CollectionView)限制在屏幕的顶部 1/3。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。