开发人员! 我刚开始学习Xamarin,创建了几页。它是如此简单。仅第一页和获取第二页的按钮。 但是,当我单击按钮时,状态栏下方出现了意外的蓝线。我该如何解决? 先感谢您!
这是我的主页:
<?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="HelloApp.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="MainPage.xaml"/>
<!-- Place new controls here -->
<Button x:Name="button1" Text="Go to Page 3" Clicked="Button_Click" />
<!-- Place new controls here -->
</StackLayout>
</ContentPage>
这是我的第二页:
<?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="HelloApp.Page3">
<ContentPage.Content>
<StackLayout>
<Label Text="Page3.xaml"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
这是我链接到第一个xaml的类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace HelloApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, EventArgs e)
{
Application.Current.MainPage = new NavigationPage(new Page3());
}
}
}
这是我的链接到第二个xaml的类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HelloApp
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page3 : ContentPage
{
public Page3 ()
{
InitializeComponent ();
}
}
}
答案 0 :(得分:1)
Application.Current.MainPage =新的Page3();
已解决!