xaml - ListView 在 iOS 上无法正确显示

标签 xaml xamarin xamarin.forms xamarin.ios

我正在编写在 ListView 中显示用户评论的 Xamarin 表单应用程序。

问题是它在 Android 上显示正确,但在 iOS 上它是开箱即用的(如屏幕截图所示)

这些项目是在运行异步网络请求收集信息后添加的,我不知道这是否会影响它。

安卓屏幕

enter image description here

iOS 屏幕

enter image description here

我的 XAML

<local:PostListView x:Name="MessageView" HasUnevenRows="True" IsPullToRefreshEnabled="True" Refreshing="MessageView_Refreshing" SeparatorVisibility="None" BackgroundColor="#7ed6df">
    <ListView.ItemTemplate>
        <DataTemplate>
            <local:PostViewCell>
                <StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
                    <Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
                        </Image.GestureRecognizers>
                    </Image>
                    <Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
                    <StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
                        <Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
                            <Image.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
                            </Image.GestureRecognizers>
                        </Image>
                        <Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
                    </StackLayout>
                </StackLayout>
            </local:PostViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</local:PostListView>

PostViewCell.cs

using SocialNetwork.iOS.Renderers;
using SocialNetwork.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(PostViewCell), typeof(PostViewCelliOS))]
namespace SocialNetwork.iOS.Renderers
{
    public class PostViewCelliOS : ViewCellRenderer
    {

        public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
        {
            var cell = base.GetCell(item, reusableCell, tv);
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            return cell;
        }
    }
}

最佳答案

您可以尝试创建一个 StackLayout 包装您的内容,如:

<local:PostViewCell>
    <StackLayout>
        <StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
            <Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
                <Image.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
                </Image.GestureRecognizers>
            </Image>
            <Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
            <StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
                <Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
                    </Image.GestureRecognizers>
                </Image>
                <Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
            </StackLayout>
        </StackLayout>
    </StackLayout>
</local:PostViewCell>

关于xaml - ListView 在 iOS 上无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48729290/

相关文章:

c# - Windows 8 用户控件示例

c# - Xamarin 工作室 "Error XA5209: Unzipping failed. Please download"

xamarin.forms - Xamarin形式:ITMS-90809:不推荐使用的API,但是我的项目中没有webview

xaml - 使用MVVM将ScrollIntoView转换为SelectedItem(Windows Phone 8.1)

xaml - 如何在文本更改时启用/禁用绑定(bind)到 ICommand 的按钮,而不是失去 TextBox 的焦点

c# - 调用 xamarin 的目标已引发异常

android - Xamarin 没有 Forms/MvvmCross/Data binding

xamarin - 发布 Windows Phone 8.1 应用程序

php - Xamarin.Forms Android 和 iOS 与 Sqlite 是否可以同步到 MySql?

c# - ListView 无法使用 Xamarin Forms 正确呈现