Xamarin.forms iOS ImageCell中的行分隔符不总是显示

Xamarin.forms iOS ImageCell中的行分隔符不总是显示,xamarin.forms,Xamarin.forms,我有一个ImageCell绑定到iOS资产。渲染时,线分隔符并不总是显示 这似乎是一个绘图问题,因为如果我向上和向下滚动一些行,将重新绘制分隔线,如屏幕截图所示 有什么想法吗 我将我的UI编码为: public class Contact{ public Contact(string name, string email) { Name = name; Email = email; Initial = "Avatar"; }

我有一个ImageCell绑定到iOS资产。渲染时,线分隔符并不总是显示

这似乎是一个绘图问题,因为如果我向上和向下滚动一些行,将重新绘制分隔线,如屏幕截图所示

有什么想法吗

我将我的UI编码为:

public class Contact{
    public Contact(string name, string email) {
        Name = name;
        Email = email;
        Initial = "Avatar";
    }

    public string Name { get; }
    public string Email { get; }
    public string Initial { get; }
}

public class ContactCell: ImageCell {

    public ContactCell() {
        this.SetBinding(TextProperty, "Name");
        this.SetBinding(DetailProperty, "Email");
        this.SetBinding(ImageSourceProperty, "Initial");
    }
}

public class ContactListPage : ContentPage {

    public ContactListPage() {
        Title = "List";

        Content = new ListView {
            RowHeight = 60,
            ItemTemplate = new DataTemplate(typeof(ContactCell)),
            Margin = new Thickness(10, 0, 0, 0),
            ItemsSource = new List<Contact> {
              new Contact("Isa Tusa", "isa.tusa@me.com"),
              .
              .
           };
        }
    }
公共类联系人{
公共联系人(字符串名称、字符串电子邮件){
名称=名称;
电子邮件=电子邮件;
首字母=“化身”;
}
公共字符串名称{get;}
公共字符串电子邮件{get;}
公共字符串首字母{get;}
}
公共类ContactCell:ImageCell{
公共联络电话(){
this.SetBinding(TextProperty,“Name”);
此设置绑定(DetailProperty,“电子邮件”);
此项。设置绑定(ImageSourceProperty,“初始”);
}
}
公共类ContactListPage:ContentPage{
公共联系人列表页(){
Title=“列表”;
内容=新列表视图{
行高=60,
ItemTemplate=新数据模板(typeof(ContactCell)),
余量=新厚度(10,0,0,0),
ItemsSource=新列表{
新联系人(“Isa Tusa”、“Isa。tusa@me.com"),
.
.
};
}
}

我认为这是使用默认viewcell模板(如图像单元格等)时的行为。我建议您使用自定义实现,如对项目模板使用网格。我们对它有更多的控制,可以轻松修改为任何所需的设计。我已修改了您的代码并粘贴在下面。检查它是否对您有用

 public ContactListPage()
    {
        Title = "List";

        Content = new ListView
        {
            RowHeight = 71,
            SeparatorVisibility = SeparatorVisibility.None,
            // ItemTemplate = new DataTemplate(typeof(ContactCell)),
            ItemTemplate = new DataTemplate(() =>
            {
                return new ViewCell { View = ContactCellGrid() };
            }),
            ItemsSource = new List<Contact> {
              new Contact("Isa Tusa", "isa.tusa@me.com"),
              new Contact("Racquel Ricciardi", "racquel.ricciardi@me.com"),
              new Contact("Teresita Mccubbin", "teresita.mccubbin@me.com"),
              new Contact("Rhoda Hassinger", "rhoda.hassinger@me.com"),
              new Contact("Carson Cupps", "carson.cupps@me.com"),
              new Contact("Devora Nantz", "devora.nantz@me.com"),
              new Contact("Tyisha Primus", "tyisha.primus@me.com"),
              new Contact("Muriel Lewellyn", "muriel.lewellyn@me.com"),
              new Contact("Hunter Giraud", "hunter.giraud@me.com"),
              }
        };
    }

    private Grid ContactCellGrid()
    {
        var grid = new Grid();
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) });

        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5, GridUnitType.Absolute) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5, GridUnitType.Absolute) });


        var nameLabel = new Label { FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center };
        var ageLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; ;
        var locationLabel = new Image { HorizontalOptions = LayoutOptions.Center };
        var boxView = new BoxView { Color = Color.Gray, HeightRequest = 1 };

        nameLabel.SetBinding(Label.TextProperty, "Name");
        ageLabel.SetBinding(Label.TextProperty, "Email");
        locationLabel.SetBinding(Image.SourceProperty, "Initial");

        grid.Children.Add(nameLabel, 2, 1);
        grid.Children.Add(ageLabel, 2, 2);

        grid.Children.Add(locationLabel, 1, 1);
        Grid.SetRowSpan(locationLabel, 2);

        grid.Children.Add(boxView, 1, 4);
        Grid.SetColumnSpan(boxView, 2);

        return grid;
    }
公共联系人列表页()
{
Title=“列表”;
内容=新列表视图
{
行高=71,
SeparatorVisibility=SeparatorVisibility.None,
//ItemTemplate=新数据模板(typeof(ContactCell)),
ItemTemplate=新数据模板(()=>
{
返回新的ViewCell{View=ContactCellGrid()};
}),
ItemsSource=新列表{
新联系人(“Isa Tusa”、“Isa。tusa@me.com"),
新联系人(“Racquel Ricciardi”,“Racquel。ricciardi@me.com"),
新联系人(“Teresita Mccubbin”,“Teresita。mccubbin@me.com"),
新联系人(“罗达哈辛格”,“罗达。hassinger@me.com"),
新联系人(“卡森杯”、“卡森杯”。cupps@me.com"),
新联系人(“Devera Nantz”,“Devera。nantz@me.com"),
新联系人(“Tyisha Primus”、“Tyisha。primus@me.com"),
新联系人(“Muriel Lewellyn”,“Muriel。lewellyn@me.com"),
新联系人(“亨特·吉拉德”、“亨特”。giraud@me.com"),
}
};
}
专用网格ContactCellGrid()
{
var grid=new grid();
grid.RowDefinitions.Add(newrowdefinition{Height=newgridlength(5,GridUnitType.Absolute)});
添加(newrowDefinition{Height=newgridLength(2,GridUnitType.Star)});
grid.RowDefinitions.Add(newrowdefinition{Height=newgridlength(1,GridUnitType.Star)});
grid.RowDefinitions.Add(newrowdefinition{Height=newgridlength(5,GridUnitType.Absolute)});
grid.RowDefinitions.Add(newrowdefinition{Height=newgridlength(1,GridUnitType.Absolute)});
Add(newColumnDefinition{Width=newGridLength(5,GridUnitType.Absolute)});
Add(newColumnDefinition{Width=newGridLength(1,GridUnitType.Auto)});
Add(newColumnDefinition{Width=newGridLength(1,GridUnitType.Star)});
Add(newColumnDefinition{Width=newGridLength(5,GridUnitType.Absolute)});
var namelab=新标签{FontAttributes=FontAttributes.Bold,VerticalTextAlignment=TextAlignment.Center};
var ageLabel=new Label{VerticalTextAlignment=TextAlignment.Start};
var locationLabel=新图像{horizontalpoptions=LayoutOptions.Center};
var-boxView=new-boxView{Color=Color.Gray,HeightRequest=1};
namelab.SetBinding(Label.TextProperty,“Name”);
ageLabel.SetBinding(Label.TextProperty,“电子邮件”);
locationLabel.SetBinding(Image.SourceProperty,“首字母”);
grid.Children.Add(名称标签,2,1);
grid.Children.Add(ageLabel,2,2);
grid.Children.Add(locationLabel,1,1);
Grid.SetRowSpan(位置标签,2);
grid.Children.Add(boxView,1,4);
Grid.SetColumnSpan(boxView,2);
返回网格;
}
下面是它的截图


我认为这是使用默认viewcell模板(如图像单元格等)时的行为。我建议您使用自定义实现,如对项目模板使用网格。我们对它有更多的控制,可以轻松修改为任何所需的设计。我已修改了您的代码并粘贴在下面。检查它是否对您有用

 public ContactListPage()
    {
        Title = "List";

        Content = new ListView
        {
            RowHeight = 71,
            SeparatorVisibility = SeparatorVisibility.None,
            // ItemTemplate = new DataTemplate(typeof(ContactCell)),
            ItemTemplate = new DataTemplate(() =>
            {
                return new ViewCell { View = ContactCellGrid() };
            }),
            ItemsSource = new List<Contact> {
              new Contact("Isa Tusa", "isa.tusa@me.com"),
              new Contact("Racquel Ricciardi", "racquel.ricciardi@me.com"),
              new Contact("Teresita Mccubbin", "teresita.mccubbin@me.com"),
              new Contact("Rhoda Hassinger", "rhoda.hassinger@me.com"),
              new Contact("Carson Cupps", "carson.cupps@me.com"),
              new Contact("Devora Nantz", "devora.nantz@me.com"),
              new Contact("Tyisha Primus", "tyisha.primus@me.com"),
              new Contact("Muriel Lewellyn", "muriel.lewellyn@me.com"),
              new Contact("Hunter Giraud", "hunter.giraud@me.com"),
              }
        };
    }

    private Grid ContactCellGrid()
    {
        var grid = new Grid();
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(5, GridUnitType.Absolute) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) });

        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5, GridUnitType.Absolute) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5, GridUnitType.Absolute) });


        var nameLabel = new Label { FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center };
        var ageLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; ;
        var locationLabel = new Image { HorizontalOptions = LayoutOptions.Center };
        var boxView = new BoxView { Color = Color.Gray, HeightRequest = 1 };

        nameLabel.SetBinding(Label.TextProperty, "Name");
        ageLabel.SetBinding(Label.TextProperty, "Email");
        locationLabel.SetBinding(Image.SourceProperty, "Initial");

        grid.Children.Add(nameLabel, 2, 1);
        grid.Children.Add(ageLabel, 2, 2);

        grid.Children.Add(locationLabel, 1, 1);
        Grid.SetRowSpan(locationLabel, 2);

        grid.Children.Add(boxView, 1, 4);
        Grid.SetColumnSpan(boxView, 2);

        return grid;
    }
公共联系人列表页()
{
Title=“列表”;
内容=新列表视图
{
行高=71,
SeparatorVisibility=SeparatorVisibility.None,
//ItemTemplate=新数据模板(typeof(ContactCell)),
ItemTemplate=新数据模板(()=>
{
返回新的ViewCell{View=ContactCellGrid()};
}),
ItemsSource=新列表{
新联系人(“Isa Tusa”、“Isa。tusa@me.com"),
新联系人(“Racquel Ricciardi”,“Racquel。ricciardi@me.com"),
新联系人(“Teresita Mccubbin”,“Teresita。mccubbin@me.com"),
新联系人(“罗达哈辛格”,“罗达。hassinger@me.com"),
新联系人(“卡森杯”、“卡森杯”。cupps@me.com"),
新联系人(“Devera Nantz”,“Devera。nantz@me.com"),
新联系人(“Tyisha Primus”、“Tyisha。primus@me.com"),
新联系人(“Muriel Lewellyn”,“Muriel。lewellyn@me.com"