Xamarin表格卡在黑屏上

时间:2019-08-08 17:47:52

标签: mvvm xamarin.forms prism

我对xamarin表单移动应用做了一些更改,当我在手机或仿真器上对其进行调试时,仅emtpt页什么都没有显示,我希望看到登录屏幕。 没有错误抛出,但应用程序无法正常工作。 在xamarin表单上使用Prism。在4.1和所有其他棱镜组件上进行了更新

[编辑]

Screenshot of this in action

这是Prism Application类

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
    }
}

在调试应用程序时,请进入OnInitialized方法,但无法导航至登录页面(等待NavigationService.NavigateAsync(“ NavigationPage / Login”);)

这是登录页面视图模型常量。码。甚至无法进入比赛。

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;
        }

我看不到输出屏幕上没有任何有用的内容。我花了整个下午时间,但没有锁

[编辑] 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>

2 个答案:

答案 0 :(得分:0)

错误是您使用StaticResource语句的方式。当您得到带有棱镜的空白页时,通常是view和/或ResourceDictionary的东西:

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

必须像这样:

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

答案 1 :(得分:0)

为了诊断为什么黑屏,最好捕获NavigationResult。 NavigationService在设计上会尝试捕获任何异常,然后将其在NavigationResult中传递回给您。这可以帮助您编写更简洁的代码,而不必到处都尝试。

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

您可以尝试添加类似的内容,以更好地了解问题所在。