Reputation: 2353
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);
}
Upvotes: 1
Views: 2235
Reputation: 18789
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
Upvotes: 4