I have made a test application in Xamarin.Forms with 2 pages. 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.
Enclosed I have a zip file of the test project.
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. If you leave it as it is nothing will happen as it hasn't been executed on the UI thread. Using Device.BeginInvokeOnMainThread
should fix that
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.