如何在自定义Xamarin.Forms ViewCell上的行之间添加分隔符空间? [英] How to add a separator space between rows on custom Xamarin.Forms ViewCell?

查看:950
本文介绍了如何在自定义Xamarin.Forms ViewCell上的行之间添加分隔符空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



目前单元格似乎被粘贴,并且 ViewCell

谢谢!

解决方案

您只需要进一步自定义 MenuCell 的布局即可。



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

<

 < ListView x:Name =lstItems/>  

XAML Code-Behind: -

  lstItems.ItemTemplate = new DataTemplate(typeof(Classes.MenuCell)); 
lstItems.ItemsSource = new string [] {Apples,Bananas,Pears,Oranges};

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),
方向= StackOrientation.Horizo​​ntal,
Horizo​​ntalOptions = 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;


$ / code $ / pre

会导致以下情况: -




In this question on Xamarin Forums https://forums.xamarin.com/discussion/20517/curved-corners-in-tableview-cells Craig Dunn teaches how to create a cell with frame.

I want to Add a space between each cell.

At present the cells seems glued, and the ViewCell doesn`t have a space property.

Thanks!

解决方案

You just have to customize the layout of the MenuCell further to achieve this.

Shown below is a version that uses a further Xamarin.Forms.Frame to create a spacing between each item with a couple other modifications:-

XAML Page:-

<ListView x:Name="lstItems" />

XAML Code-Behind:-

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

ViewCell class:-

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;            
    }
}

Will result in the following:-

这篇关于如何在自定义Xamarin.Forms ViewCell上的行之间添加分隔符空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆