2
votes

I'm working on a Xamarin Forms Portable project where i have a Splash-Screen, a login page and a dashboard.

If i login correctly to the app i'm storing the user on a Sqlite database.

When i try to login and the user is saved on the database i should go directly to the Dashboard (Master-Detail Page).

In Android this is working correctly but in Windows it doesn't work. This is the code of my splash screen:

public class SplashScreen : ContentPage
{
    public SplashScreen()
    {
        this.Padding = new Thickness(20, Device.OnPlatform<double>(40, 20, 20), 20, 20);

        StackLayout panel = new StackLayout
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical,
            Spacing = 15,
        };

        panel.Children.Add(new Image
        {
            Aspect = Aspect.AspectFit,
            Source = Device.OnPlatform(
                    iOS: ImageSource.FromFile("Resources/login.png"),
                    Android: ImageSource.FromFile("login.png"),
                    WinPhone: ImageSource.FromFile("Assets/login.png"))
        }
        );

        panel.Children.Add(new Label
        {
            Text = "Splash",
        });

        this.Content = panel;

        loguearseSiSePuede();

    }

    private async void loguearseSiSePuede()
    {
        UserLoginDB userDB = new UserLoginDB();
        IEnumerable<UserLogin> users = userDB.getUsers();
        var items = users.ToList();
        Debug.WriteLine("usuario: " + items.Count());
        if (items.Count() > 0)
        {
            var secondpage = new MasterDetail();
            await Navigation.PushAsync(secondpage);
        }
        else
        {
            var secondpage = new Login();
            await Navigation.PushAsync(secondpage);
        }
    }
}

The log Debug.WriteLine("usuario: " + items.Count()); is printing 1, so the user is stored correctly in the database but on, Windows the app loads the splashscreen and it won't navigate to any screen.

Does anyone knows why is this not working on Windows?

Thanks in advance

1
loguearseSiSePuede is an async method, you should call it with await. But I think you should create the SplashScreen in another way: codeworks.it/blog/?p=294 - Alessandro Caliaro
Thanks for the tip @AlessandroCaliaro. I can't call an async method in the constructor...any possible solution? - n4h1n
I think you are not working correctly. You are creating SplashScreen and (in the same moment), Pushing another page... Take a look to the link I have posted and change your way to create a SplashScreen, then in App.cs create your first page (Login or MasterDetail) - Alessandro Caliaro
I'm working correcting the splash. I've moved the control to the App.cs and now it's navigating correctly! - n4h1n
@AlessandroCaliaro i've implemented the splashscreen following the tutorial and it works perfect! Thanks a lot! - n4h1n

1 Answers

0
votes

Thanks to Alessandro this question has been answered. I've moved the control to App.cs and the App it's working OK