如何在自定义Xamarin.Forms ViewCell上的行之间添加分隔符空间?

Ine*_*oid 4 c# grid listview custom-cell xamarin.forms

在关于Xamarin论坛的这个问题中,https: //forums.xamarin.com/discussion/20517/curved-corners-in-tableview-cells Craig Dunn教授如何使用框架创建单元格.

我想在每个单元格之间添加一个空格.

目前细胞似乎是胶合的,并且ViewCell没有空间特性.

谢谢!

Pet*_*ete 8

您只需要进一步自定义布局MenuCell即可实现此目的.

下面显示的是一个版本,它使用另一个版本Xamarin.Forms.Frame在每个项目之间创建一个间距,并进行一些其他修改: -

XAML页面: -

<ListView x:Name="lstItems" />
Run Code Online (Sandbox Code Playgroud)

XAML代码 - 背后: -

lstItems.ItemTemplate = new DataTemplate(typeof(Classes.MenuCell));
lstItems.ItemsSource = new string[] { "Apples", "Bananas", "Pears", "Oranges" };
Run Code Online (Sandbox Code Playgroud)

ViewCell类: -

public class MenuCell : ViewCell
{
    public MenuCell()
    {
        Label objLabel = new Label
        {
            YAlign = TextAlignment.Center,
            TextColor = Color.Yellow,                
        };
        objLabel.SetBinding(Label.TextProperty, new Binding("."));


        StackLayout objLayout = new StackLayout
        {
            Padding = new Thickness(20, 0, 0, 0),
            Orientation = StackOrientation.Horizontal,
            HorizontalOptions = LayoutOptions.StartAndExpand,
            Children = { objLabel }
        };

        Frame objFrame_Inner = new Frame
        {
            Padding = new Thickness(15, 15, 15, 15),
            HeightRequest = 36,
            OutlineColor = Color.Accent,
            BackgroundColor = Color.Blue,
            Content = objLayout,                
        };

        Frame objFrame_Outer = new Frame
        {
            Padding = new Thickness(0, 0, 0, 10),
            Content = objFrame_Inner
        };

        View = objFrame_Outer;            
    }
}
Run Code Online (Sandbox Code Playgroud)

将导致以下结果: -

ListView与每个项目之间的间距.