【发布时间】:2019-12-16 11:51:30
【问题描述】:
我对 xamarin 形式的移动应用程序进行了一些更改,当我在手机或模拟器上调试它时,什么都没有显示,只是我希望看到登录屏幕的 emtpt 页面。 没有错误抛出,但应用程序无法正常工作。 在 xamarin 表单上使用 Prism。在 4.1 和所有其他 prism 组件上更新
[编辑]
这是 Prism 应用程序类
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");)
这是登录页面视图模型常量。代码。连cons都进不去。
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;
}
我看不到任何有用的输出屏幕。我花了整整一个下午,但没有锁定
[编辑] 应用程序.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>
【问题讨论】:
-
我认为您忘记在 prism 中注册您的登录页面,即将
containerRegistry.RegisterForNavigation<Login>();放入 RegisterTypes 方法中。 -
在prism中我们需要注册我们想要导航到的应用页面,包括“NavigationPage”:
containerRegistry.RegisterForNavigation<NavigationPage>(); -
//导航页面 containerRegistry.RegisterForNavigation
(); containerRegistry.RegisterForNavigation (); //登录和主页 containerRegistry.RegisterForNavigation (); containerRegistry.RegisterForNavigation (); containerRegistry.RegisterForNavigation ();我的所有页面都已注册。
标签: mvvm xamarin.forms prism