【问题标题】:Xamarin Forms page not showing (iOS)Xamarin 表单页面未显示 (iOS)
【发布时间】:2015-02-02 05:05:31
【问题描述】:

我在 Xamarin.Forms 中制作了一个包含 2 页的测试应用程序。主页是我要放置登录页面的堆栈的开始。 PushModalAsync 后登录页面不显示。

附上我有一个测试项目的 zip 文件。

TestProject

    public static async void StartLogin()
    {

        Button btnLogin = new Button();
        btnLogin.Text = "Login";
        btnLogin.BackgroundColor = Color.Green;
        btnLogin.TextColor = Color.White;

        ContentPage _loginPage = new ContentPage
                                 {
                                         Title = "Login",
                                         Content = new StackLayout
                                                   {
                                                           Spacing = 20,
                                                           Padding = 50,
                                                           VerticalOptions = LayoutOptions.Center,
                                                           Children =
                                                           {

                                                                   btnLogin,
                                                           }
                                                   }
                                 };
        _loginPage.BackgroundColor = Color.Black;


        await Navigation.PushAsync(_loginPage);

    }

【问题讨论】:

  • StartLogin() 在 AppDelegate 类的 FinishedLaunching 方法中被调用。

标签: c# ios xamarin.ios xamarin xamarin.forms


【解决方案1】:

试试:

Device.BeginInvokeOnMainThread(() => Navigation.PushAsync(_loginPage););

因为导航是一个 UI 操作,它必须在 UI 线程上执行。如果您将其保留为原样,则不会发生任何事情,因为它尚未在 UI 线程上执行。使用Device.BeginInvokeOnMainThread 应该可以解决这个问题

【讨论】:

  • 不幸的是问题仍然存在。
猜你喜欢
  • 2021-10-15
  • 2021-07-12
  • 2014-09-26
  • 1970-01-01
  • 2018-04-30
  • 2019-05-13
  • 2018-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多