Hello World 使用 Xamarin Studio Xamarin.Forms

在 OS X 上成功安装 Xamarin Studio 之后。现在是第一个 Hello World 应用程序的时候了。

Hello World Application:Xamarin.Forms

什么是 Xamarin 表格:

Xamarin.Forms 是一个新的库,使你能够从单个共享 C#代码库为 iOS,Android 和 Windows Phone 构建本机 UI。它提供了 40 多个跨平台控件和布局,这些控件和布局在运行时映射到本机控件,这意味着你的用户界面完全是本机的

步骤 1:

创建新的解决方案。

点击新解决方案 StackOverflow 文档

步骤 2: 选择 Forms App 并单击 Next StackOverflow 文档

步骤 3: 添加 App name,然后单击 Next StackOverflow 文档

这是创建解决方案时项目限制的样子:

StackOverflow 文档

App.xaml 中:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="HelloXamarinForms.App">
    <Application.Resources>
        <!-- Application resource dictionary -->
    </Application.Resources>
</Application>

App.xaml.cs:

using Xamarin.Forms;

namespace HelloXamarinForms
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new HelloXamarinFormsPage();
        }

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

HelloXamarinFormsPage.xaml

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:HelloXamarinForms"
    x:Class="HelloXamarinForms.HelloXamarinFormsPage">

    <Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center"
        HorizontalOptions="Center" />
</ContentPage>

HelloXamarinFormsPage.xaml.cs

using Xamarin.Forms;

namespace HelloXamarinForms
{
    public partial class HelloXamarinFormsPage : ContentPage
    {
        public HelloXamarinFormsPage()
        {
            InitializeComponent();
        }
    }
}