Fork me on GitHub

xamarin.forms 主明细界面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;

using Xamarin.Forms;

namespace PageApp
{
    public class MainMasterPage : MasterDetailPage
    {
        public MainMasterPage()
        {
            Label header = new Label
            {
                Text = "MasterDetailPage",
                Font = Font.BoldSystemFontOfSize(30),
                HorizontalOptions = LayoutOptions.Center
            };
            int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 11, 22, 112 };
            ListView listView = new ListView
            {
                ItemsSource = a
            };
            listView.ItemSelected += ListView_ItemSelected;
            Master = new ContentPage
            {
                Title = header.Text,
                Content = new StackLayout
                {
                    Children =
                    {
                        header,
                        listView
                    }
                }
            };
            Detail = new ContentPage() { Content = new Label() { Text = "测试" } };
        }

        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            this.Detail = new ContentPage() { Content = new Label() { Text =  e.SelectedItem.ToString() } };
            //if (Device.OS == TargetPlatform.Android)
            //{
            //    this.Navigation.PopAsync();
                
            //}
        }
    }
}

  

posted @ 2017-03-10 14:52  开发软件  阅读(210)  评论(0编辑  收藏  举报