简体   繁体   English

Xamarin表单页面未显示(iOS)

[英]Xamarin Forms page not showing (iOS)

I have made a test application in Xamarin.Forms with 2 pages. 我在Xamarin.Forms中做了一个2页的测试应用程序。 The main page is the start of the stack on which I want to put a login page. 主页是我要放置登录页面的堆栈的开始。 After PushModalAsync the login page does not show. PushModalAsync之后,不会显示登录页面。

Enclosed I have a zip file of the test project. 附上我有测试项目的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);

    }

Try: 尝试:

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

Because Navigation is a UI operation it must be executed on the UI thread. 由于导航是UI操作,因此必须在UI线程上执行。 If you leave it as it is nothing will happen as it hasn't been executed on the UI thread. 如果您将其保留为原样,则不会发生任何事情,因为尚未在UI线程上执行它。 Using Device.BeginInvokeOnMainThread should fix that 使用Device.BeginInvokeOnMainThread应该可以解决该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM