首页 文章

当我点击xamarin中的按钮时,发生了未处理的异常xamarin.forms

提问于
浏览
0

我的项目代码:

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中:

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

在我在android模拟器中单击按钮时,我在xamarin创建的每个项目中都会收到此消息:

enter image description here

发生了未处理的异常 .

当我点击其他项目中的按钮时,它会给我相同的消息,请帮助我!

1 回答

  • 0

    所以我发现我必须在MainPage = new exercice2_stack_layout.MainPage()中更改app.xaml.cs中的这一行; to Mainpage = new NavigationPage(new MainPage());使navigation.pushasync完美地工作 .

相关问题