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:
建立新的解決方案。
點選新解決方案
步驟 2: 選擇 Forms App 並單擊 Next
步驟 3: 新增 App name,然後單擊 Next
這是建立解決方案時專案限制的樣子:
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();
}
}
}