Xamarin.Forms Hello word

  1. 创建项目

Xamarin.Forms Hello word

Xamarin.Forms Hello word

XMD1右键-》添加-》新建项目

MDPage:MasterDetailPage

主窗体,导航与明细的布局窗体。

指定MenuPage.xaml 作为Master

<?xml
version="1.0"
encoding="utf-8" ?>

<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

x:Class="XMD1.Page.MenuPage"

Title="MenTitle"

BackgroundColor="#53ba9d">

<ContentPage.BackgroundColor>

<OnPlatform
x:TypeArguments="Color"

Android="#F5F5F5" />

</ContentPage.BackgroundColor>

<ContentPage.Content>

<ListView
x:Name="EmployeeView">

<ListView.ItemTemplate>

<DataTemplate>

<TextCell
Text="{Binding DisplayName}" />

</DataTemplate>

</ListView.ItemTemplate>

</ListView>

</ContentPage.Content>

</ContentPage>

指定ListView作为导航窗体

添加行选择事件

//行选择事件

this.EmployeeView.ItemSelected += (sender, e) =>

{

if (EmployeeView.SelectedItem == null)

return;

 

root.NavigateAsync(((PageTypeGroup)e.SelectedItem).DisplayName);//((HomeMenuItem)e.SelectedItem).MenuType

};

MDPage
事件NavigateAsync初始化窗体事件

///
<summary>

/// 导航窗体

///
</summary>

///
<param name="displayName"></param>

internal
async
void NavigateAsync(string displayName)

{

NavigationPage newPage;

if (!Pages.Any(p => p.Key.Equals(displayName)))

{

switch (displayName)

{

case
"DataGridPage":

var tpage = new
NavigationPage(new
DataGridPage());

Pages.Add(displayName, tpage);

break;

}

}

newPage = Pages[displayName];

if (newPage == null)

return;

 

//pop to root for Windows Phone

if (Detail != null && Device.OS == TargetPlatform.WinPhone)

{

await Detail.Navigation.PopToRootAsync();

}

 

Detail = newPage;

 

if (Device.Idiom != TargetIdiom.Tablet)

IsPresented = false;

}

上一篇:C++模板(基础)


下一篇:VC编程中如何设置对话框的背景颜色和静态文本颜色