XF 自定义表视图

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace App28
{
    public partial class App : Application
    {
        public App ()
        {
            InitializeComponent();

            MainPage = new ContentPage
            {
                Content = new TableView
                {
                    Root = new TableRoot("生日表格")
                    {
                        new TableSection("")
                        {
                            KeyValueCell("zhangsan","1998-01-01"),
                            KeyValueCell("lisi","1999-01-01"),
                            KeyValueCell("wangwu","2008-01-01"),
                            KeyValueCell("zhaoliu","2018-01-01"),
                        }
                    }
                }
            };
        }

        public Cell KeyValueCell(string name,string date)
        {
            var customCell = new ViewCell
            {
                View = new StackLayout
                {
                    Children =
                    {
                        new Label{Text=name},
                        new Label{Text=date,TextColor=Color.Green}

                    }
                }
            };
            return customCell;
        }

        protected override void OnStart ()
        {
            // Handle when your app starts
        }

        protected override void OnSleep ()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume ()
        {
            // Handle when your app resumes
        }
    }
}
 

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/81462734