[英]An unhandled exception occured xamarin.forms when i click a button in xamarin
The code of my project: 我项目的代码:
MainPage.xaml.cs: MainPage.xaml.cs中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App2
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
}
}
MainPage.xaml: 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:App2"
x:Class="App2.MainPage">
<Button Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" Clicked="Button_Clicked" />
</ContentPage>
In every project i create in xamarin when i click a button when in the android emulator i receive this message : 当我在android模拟器中单击一个按钮时,在xamarin中创建的每个项目中,我都会收到以下消息:
enter image description here 在此处输入图片说明
An unhandled exception occured. 发生未处理的异常。
And when i click the button in others projects it's give me the same message, please help me ! 当我单击其他项目中的按钮时,也会给我同样的信息,请帮帮我!
So i found that i have to change this line in app.xaml.cs from MainPage = new exercice2_stack_layout.MainPage(); 所以我发现我必须从MainPage = new exercice2_stack_layout.MainPage();更改app.xaml.cs中的这一行。 to Mainpage = new NavigationPage (new MainPage());
到Mainpage = new NavigationPage(new MainPage()); to make the navigation.pushasync work perfectly .
使navigation.pushasync完美地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.