【问题标题】:Xamarin.Forms - PushAsync is not supported globally on Android, please use a NavigationPageXamarin.Forms - Android 全球不支持 PushAsync,请使用 NavigationPage
【发布时间】:2020-05-21 13:54:21
【问题描述】:

我正在尝试做的是在用户注册并单击“是”后,它将转到登录页面。否则用户单击“取消”它将进行注册,请帮帮我..我是 xamarin 的新手

    void Handle_Clicked(object sender, System.EventArgs e)
    {
      string ConnectionString = "Server=10.0.2.2; Port=5432;User Id=postgres; Password=ncf123; Database=Accounting";
            try
            {
                NpgsqlConnection connection = new NpgsqlConnection(ConnectionString);
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("adi na");

            }
            NpgsqlConnection connections = new NpgsqlConnection(ConnectionString);
            connections.Open();
            NpgsqlCommand command = connections.CreateCommand();
            command.CommandText = "INSERT INTO account(username, password, email, phonenumber) VALUES ( '" + EntryUsername.Text + "', '" + EntryPassword.Text + "','" + EntrEmail.Text + "','" + EntryPhoneNumber.Text + "')";
            try
            {
                NpgsqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    EntryUsername.Text = reader[0].ToString();
                    EntryPassword.Text = reader[1].ToString();
                    EntrEmail.Text = reader[2].ToString();
                    EntryPhoneNumber.Text = reader[3].ToString();

                }
            connections.Close();
            Device.BeginInvokeOnMainThread(async () =>
            {
                var result = await DisplayAlert("Congratulations", "User Registration Successfull", "Yes", "Cancel");
                if (result)
                {
                    await Navigation.PushAsync(new LoginPage());
                }
                else
                {
                    await Navigation.PushAsync(new registration());
                }

            });

        }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

更新 这是我的 App.xaml.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new registration();
    }

    protected override void OnStart()
    {
    }

    protected override void OnSleep()
    {
    }

    protected override void OnResume()
    {
    }
}

请帮帮我,我是 xamarin 和 postgresql 的新手

【问题讨论】:

  • 正如错误所说,您需要使用 NavigationPage。您需要将当前页面包装在 NavigationPage 中,很可能是在 App.xaml.cs 中分配 MainPage 时
  • @Jason 先生怎么样?
  • MainPage = new NavigationPage(new WhateverMyMainPageIsCalled());
  • 为什么是主页?我可以用 LoginPage 替换它吗?但我已经试过了,但它不起作用

标签: xamarin xamarin.forms xamarin.android navigation


【解决方案1】:

在您的 app.cs 中更改 MainPage = new MainPage();到 MainPage = new NavigationPage(new MainPage()); 其中 MainPage() 是启动应用时要打开的页面的名称

【讨论】:

  • var result = await DisplayAlert("恭喜", "用户注册成功", "是", "取消"); if (result) { MainPage = new NavigationPage(new MainPage()); } """错误 MainPage 是类型,但像变量一样使用
  • 我更改了我的 app.xaml
  • 查看您的 app.xaml.cs 您希望它说 MainPage = new NavigationPage(new registration());其他一切看起来都很好
  • 是的,注册后用户会选择是否登录,如果该人点击,那么他将链接到登录页面
  • 现在可以用了吗?将该更改添加到您的 app.xaml.cs 应该可以解决问题
猜你喜欢
  • 2014-08-28
  • 2018-11-18
  • 2017-12-19
  • 2020-05-04
  • 2018-01-13
  • 2019-08-14
  • 2017-08-26
  • 1970-01-01
  • 2018-06-12
相关资源
最近更新 更多