【问题标题】:Blank Space Visible on Xamarin Forms iOS Only仅在 Xamarin 窗体 iOS 上可见的空白区域
【发布时间】:2022-01-01 07:44:56
【问题描述】:

Xamarin Forms iOS 上的列表视图问题

你好,我有一个跨平台的应用程序,我放了一个包含一些项目的 ListView,在 android 上没问题,但在 iOS 上,有一个我无法纠正的空白... 我已经查看了代码,但找不到问题所在。

有没有人看到这个错误或已经经历过这个错误?

这是我的图片:

  1. 空白是我的内容页面。
  2. 黄色是我的 ListView。
  3. 蓝色方块是我无法删除的空白。
  4. 红色是我列表的标题。

这是我的代码:

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="MensagemDoDia.Views.MensagemViews.MensagemDetailPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:extended="clr-namespace:MensagemDoDia.Engine.InfiniteScrolling"
    xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
    xmlns:pancake="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
    ios:Page.UseSafeArea="True">
    <ContentPage.Content>
        <Grid>
            <ListView
                BackgroundColor="Yellow"
                CachingStrategy="RecycleElement"
                HasUnevenRows="True"
                ItemSelected="ListView_ItemSelected"
                ItemsSource="{Binding ListaMensagem}"
                Scrolled="ListView_Scrolled"
                SeparatorVisibility="None">
                <ListView.Behaviors>
                    <extended:InfiniteScrollBehavior IsLoadingMore="{Binding IsBusy}" />
                </ListView.Behaviors>

                <ListView.Header>

                    <StackLayout
                        Margin="{OnPlatform Android='10,0,10,0',
                                            iOS='10,0,10,0'}"
                        BackgroundColor="Red"
                        HeightRequest="{OnPlatform Android=80,
                                                   iOS=70}"
                        Orientation="Horizontal">

                        <Button
                            Clicked="ButtonVoltar_Clicked"
                            Style="{StaticResource ButtonVoltarStyle}"
                            Text="{StaticResource FontAwesome_ArrowLeft}"
                            VerticalOptions="Center" />

                        <Label
                            x:Name="LabelNomeCategoria"
                            FontSize="Medium"
                            Opacity="0.7"
                            Style="{StaticResource LabelBoldStyle}"
                            VerticalTextAlignment="Center" />

                    </StackLayout>

                </ListView.Header>

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <pancake:PancakeView
                                Margin="10,5"
                                Padding="0"
                                BackgroundColor="WhiteSmoke"
                                CornerRadius="15"
                                VerticalOptions="CenterAndExpand">

                                <pancake:PancakeView.Shadow>
                                    <pancake:DropShadow BlurRadius="1" Color="Black" />
                                </pancake:PancakeView.Shadow>

                                <Grid RowDefinitions="*, 50" RowSpacing="0">
                                    <Frame
                                        Padding="0"
                                        BackgroundColor="Gray"
                                        CornerRadius="15"
                                        HasShadow="False"
                                        HorizontalOptions="FillAndExpand"
                                        VerticalOptions="FillAndExpand">
                                        <Grid>

                                            <Label
                                                Margin="20,30"
                                                FontAttributes="Bold"
                                                FontSize="Medium"
                                                HorizontalOptions="FillAndExpand"
                                                HorizontalTextAlignment="Center"
                                                Style="{StaticResource LabelMediumStyle}"
                                                Text="{Binding MensagemTexto}"
                                                TextColor="White"
                                                TextType="Html"
                                                VerticalOptions="FillAndExpand"
                                                VerticalTextAlignment="Center" />

                                        </Grid>
                                    </Frame>

                                    <Grid
                                        Grid.Row="1"
                                        ColumnDefinitions="*, auto, auto, auto"
                                        ColumnSpacing="0">

                                        <Label
                                            Margin="15,0,0,0"
                                            AutomationId="{Binding MensagemAutor}"
                                            FontSize="Small"
                                            HorizontalTextAlignment="Start"
                                            LineBreakMode="TailTruncation"
                                            MaxLines="1"
                                            Opacity="0.7"
                                            Style="{StaticResource LabelStyle}"
                                            Text="{Binding MensagemAutor}"
                                            TextColor="Black"
                                            VerticalTextAlignment="Center">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Tapped="LabelAutor_Tapped" />
                                            </Label.GestureRecognizers>
                                        </Label>

                                        <Button
                                            Grid.Column="1"
                                            AutomationId="{Binding Chave}"
                                            Clicked="ButtonCopiarMensagem_Clicked"
                                            CornerRadius="15"
                                            FontFamily="{StaticResource FontAwesome}"
                                            FontSize="Medium"
                                            Style="{StaticResource ButtonIconeStyle}"
                                            Text="{StaticResource FontAwesome_Paste}"
                                            VerticalOptions="CenterAndExpand"
                                            WidthRequest="45" />

                                        <Button
                                            x:Name="ButtonCompartilhar"
                                            Grid.Column="2"
                                            AutomationId="{Binding Chave}"
                                            Clicked="ButtonCompartilhar_Clicked"
                                            CornerRadius="15"
                                            FontFamily="{StaticResource FontAwesome}"
                                            FontSize="Medium"
                                            Style="{StaticResource ButtonIconeStyle}"
                                            Text="{StaticResource FontAwesome_ShareAll}"
                                            VerticalOptions="CenterAndExpand"
                                            WidthRequest="45" />
                                        <Button
                                            x:Name="ButtonFavorito"
                                            Grid.Column="3"
                                            Margin="0,0,5,0"
                                            Clicked="ButtonFavoritar_Clicked"
                                            CornerRadius="15"
                                            FontFamily="{StaticResource FontAwesome}"
                                            FontSize="Medium"
                                            HorizontalOptions="EndAndExpand"
                                            Style="{StaticResource ButtonIconeStyle}"
                                            Text="{StaticResource FontAwesome_Heart}"
                                            VerticalOptions="CenterAndExpand"
                                            WidthRequest="45" />
                                    </Grid>

                                </Grid>
                            </pancake:PancakeView>
                        </ViewCell>
                    </DataTemplate>


                </ListView.ItemTemplate>

                <ListView.Footer>
                    <Grid Padding="6" IsVisible="{Binding IsBusy}">
                        <Grid.Triggers>
                            <Trigger TargetType="Grid" Property="IsVisible" Value="False">
                                <Setter Property="HeightRequest" Value="0" />
                            </Trigger>
                        </Grid.Triggers>
                        <Label
                            HorizontalOptions="Center"
                            Text="Loading..."
                            VerticalOptions="Center" />
                    </Grid>
                </ListView.Footer>

            </ListView>
        </Grid>
    </ContentPage.Content>
</ContentPage>

【问题讨论】:

  • 您的页面是否包含在 NavigationPage 中?
  • @Jason 没有导航页

标签: c# .net xaml xamarin


【解决方案1】:

VerticalAlignment 添加到ListView 并将其设置为TopStretch。可能对StackLayout 做同样的事情。


如果父 Grid 没有持有除 ListView 之外的其他项目,您可以选择删除它;因此使ListView 成为ContentPage 的唯一孩子,这是有效的。

【讨论】:

  • 我尝试了 VerticalOptions 提到的所有方法,但我没有成功:/
  • 如果您删除 ListView 并添加不同的控件,只说 Label 会发生同样的情况吗?
  • 在模拟器实际设备上也会发生这种情况吗?
  • 我删除并放置了另一个组件,同样的事情没有发生,一切都很好。
  • 那么浮动的ListView 的填充/边距有什么不同。 (我知道它不应该发生,但确实如此)......所以这种差异可能会导致您遇到 IOS/解决方法的问题。总帐
猜你喜欢
  • 2015-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-12-30
  • 2020-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
相关资源
最近更新 更多