S. Aziz Kazdal
S. Aziz Kazdal

Reputation: 1186

xamarin form stuck on blank screen

I did some changes xamarin form mobile app and when I debug it on my phone or an emulator nothing shows up just emtpt page which I expect to see login screen. No error throw but app does not working. Using Prism on xamarin forms. Updated on 4.1 and all other prism component up to date

[Edit]

Image

This is the Prism Application class

public partial class App : PrismApplication
    {
        public App() : this(null) { }

    public App(IPlatformInitializer initializer) : base(initializer) { }

    protected override async void OnInitialized()
    {
        //LiveReload.Init();
        HotReloader.Current.Run(this);
        InitializeComponent();
        await NavigationService.NavigateAsync("NavigationPage/Login");
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        new PageRegister(containerRegistry);
        new ServiceRegister(containerRegistry);
    }

    protected override void OnStart()
    {
        // Handle when your app starts
    }

    protected override void OnSleep()
    {
        // Handle when your app sleeps
        var huC = ApplicationSettings.HubConnection;
    }

    protected override void OnResume()
    {
        // Handle when your app resumes
    }
}

When debugging application get in the OnInitialized methods but can not navigate to Login page (await NavigationService.NavigateAsync("NavigationPage/Login");)

This is the login page view models const. code. Cannot get in even conts.

public LoginViewModel(INavigationService navigationService, ILoginMethod _loginMethod,
            IPageDialogService _dialogService, IPagingParams _pagingParams) : base(navigationService, _dialogService)
        {
            //commands
            NavigateCommand = new DelegateCommand<string>(Navigate);
            Login = new DelegateCommand(LoginCommand);

            DialogService = _dialogService;
            LoginMethod = _loginMethod;
            PagingParams = _pagingParams;

            LoginModel = new LoginModel();
            UserLoginModel = new ApplicationUserLoginModel();

            ActivityIsRunning = false;
            ActivityIsVisible = false;
            LoginButtonEnabled = true;

            LoginMethod.HttpConnection.Parameters.BaseUrl = ApplicationSettings.BaseUrl;
            LoginMethod.HttpConnection.Parameters.Port = ApplicationSettings.Port;
            LoginMethod.HttpConnection.Parameters.Connection = ApplicationSettings.Connection;
            LoginMethod.HttpConnection.Parameters.Version = ApplicationSettings.Version;
            LoginMethod.HttpConnection.Parameters.MediaTypeHeader = ApplicationSettings.MediaTypeHeader;

            PageFooterMessage = "KURUMSAL FİRMA UYGULAMASI";
            HeaderImageUrl = ApplicationSettings.LoginScreeenLogo;

            PagingParams.PageSize = ApplicationSettings.PagingPageDefaultSize;
            PagingParams.PageIndex = ApplicationSettings.PagingPageDefaultIndex;
        }

Nothing in output screen usefull I can can see. I spent whole afternoon on this but no lock

[Edit] App.xaml

    <?xml version="1.0" encoding="utf-8" ?>
<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms"
             x:Class="Q.Mobile.Corporate.App">
    <Application.Resources>
        <ResourceDictionary>
            <!--<Color x:Key="ColorPrimary">#795548</Color>
            <Color x:Key="ColorPrimaryDark">#4b2c20</Color>
            <Color x:Key="ColorPrimaryLight">#a98274</Color>-->

            <Color x:Key="ColorPrimary">#1976d2</Color>
            <Color x:Key="ColorPrimaryDark">#26629e</Color>
            <Color x:Key="ColorPrimaryLight">#5199e0</Color>
            <Color x:Key="ColorPrimaryBackGround">#f5f5f5</Color>

            <Color x:Key="ColorListItemBackGround">#f0eded</Color>

            <Color x:Key="CyanColorPrimary">#00838f</Color>
            <Color x:Key="CyanColorPrimaryDark">#005662</Color>
            <Color x:Key="CyanColorPrimaryLight">#4fb3bf</Color>

            <Color x:Key="BlueColorPrimary">#0d47a1</Color>
            <Color x:Key="BlueColorPrimaryDark">#002171</Color>
            <Color x:Key="BlueColorPrimaryLight">#5472d3</Color>

            <Color x:Key="GreyBackground">#e0e0e0</Color>
            <Color x:Key="AmberActivityIndicator">#ffab00</Color>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

Login.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Q.Mobile.Corporate.Views.Login.Login"
             NavigationPage.HasNavigationBar="False"
             Visual ="Material">
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness">
            <On Platform="iOS" Value="0, 20, 0, 0"/>
        </OnPlatform>
    </ContentPage.Padding>
    <ContentPage.Content>
        <Grid BackgroundColor="{StaticResource Key=ColorPrimaryBackGround}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackLayout Grid.Row="1" Padding="0,40,0,0" >
                <Image Source="mobile_app_login_screen.png" VerticalOptions="Center"/>
            </StackLayout>
            <StackLayout Grid.Row="2" Padding="30,20,30,0">
                <Entry Placeholder="Kullanıcı Adı" Text="{Binding Username}"/>
                <Entry Placeholder="Şifre" Text="{Binding Password}"/>
                <Button Text="GİRİŞ" IsEnabled="{Binding LoginButtonEnabled}"
                        Command="{Binding Login}"                        
                        Margin="0,20,0,0" CornerRadius="5"
                        TextColor="White" FontAttributes="Bold"
                        HeightRequest="50">
                </Button>
                <ActivityIndicator VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
                                   Color="{StaticResource Key=AmberActivityIndicator}"
                                   IsVisible="{Binding ActivityIsVisible}"
                                   IsRunning="{Binding ActivityIsRunning}" />
            </StackLayout>

            <StackLayout Grid.Row="4" HorizontalOptions="Center" VerticalOptions="End">
                <Label Text="{Binding PageFooterMessage}"/>
            </StackLayout>

        </Grid>
    </ContentPage.Content>
</ContentPage>

Upvotes: 2

Views: 4778

Answers (2)

Umar3x
Umar3x

Reputation: 1084

The error is how you use the StaticResource statement. When you got a blank page with prism this is often something with view and/or ResourceDictionary :

Color="{StaticResource Key=AmberActivityIndicator}"
BackgroundColor="{StaticResource Key=ColorPrimaryBackGround}"

Just have to be like that :

Color="{StaticResource AmberActivityIndicator}"
BackgroundColor="{StaticResource ColorPrimaryBackGround}"

EDIT : As per below comment, anyone meeting this issue, try to disable hot reload.

Upvotes: 0

Dan Siegel
Dan Siegel

Reputation: 5799

In order to diagnose why you have a blank screen it is best to capture the NavigationResult. The NavigationService by design attempts to catch any exception which it then passes back to you in the NavigationResult. This helps you to write cleaner code without having to put a try catch everywhere.

var result = await NavigationService.NavigateAsync("SomePage");
if(!result.Success)
{
    Console.WriteLine(result.Exception);
    Debugger.Break();
}

You might try adding something like this to better see what went wrong.

Upvotes: 4

Related Questions