App.xaml.cs
namespace NaviLogin
{
public partial class App : Application
{
public App()
{
InitializeComponent();
// 一開始顯示 Login 畫面
MainPage = new Login();
}
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
}
}
}
Login.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"
x:Class="NaviLogin.Login">
<ContentPage.Content>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<StackLayout Orientation="Horizontal">
<Label Text="帳號"/>
<Entry WidthRequest="100"></Entry>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="密碼"/>
<Entry WidthRequest="100"></Entry>
</StackLayout>
<Button x:Name="btnLogin" Text="登錄" Clicked="BtnLogin_Clicked"></Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Login.xaml.csnamespace NaviLogin
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Login : ContentPage
{
public Login()
{
InitializeComponent();
}
private void BtnLogin_Clicked(object sender, EventArgs e)
{
// 登錄後把 MainPage 置換掉
App.Current.MainPage = new NavigationPage(new MainPage());
}
}
}
MainPage.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:NaviLogin"
x:Class="NaviLogin.MainPage"
Title="主頁面">
<Label Text="回不去囉"
VerticalOptions="Center"
HorizontalOptions="Center" />
</ContentPage>
沒有留言:
張貼留言