如何使用 Fresh.MVVM 在 Xamarin.Forms 中浏览模式页面
How to navigate through modal pages in Xamarin.Forms using Fresh.MVVM
我试图在按下按钮时使用 MVVM 在我的 xamarin 表单应用程序中推送模式页面。我已经知道如何使用导航堆栈,但不知道如何将内容页面用作模态页面,我尝试了多种方法,尤其是调用 PushPageModel 方法。
这是我尝试过的最后一件事:
查看或页面:
<Label
x:Name="forgottenPasswordLabel"
Text="Forgot password?"
TextColor="LightPink"
FontSize="16"
FontAttributes="Bold"
VerticalOptions="Start"
HorizontalOptions="End"
Margin="25,0,25,25">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ForgotPasswordCommand}"/>
</Label.GestureRecognizers>
</Label>
视图模型class:
public class LogInViewModel : FreshBasePageModel
{
public ICommand ForgotPasswordCommand { get; set; }
public LogInViewModel()
{
}
public override void Init(object initData)
{
ForgotPasswordCommand = new Command (async() =>
{
var newPage = FreshPageModelResolver.ResolvePageModel<ForgottenPasswordViewModel>();
await CoreMethods.PushPageModel<ForgottenPasswordViewModel>(null, false, true);
});
}
}
App.xaml.cs class:
public App()
{
InitializeComponent();
MainPage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
}
此代码给出以下错误:"FreshTinyIoC.TinyIoCResolutionException: 'Resolve failed: IFreshNavigationService"
就是这样,如果您需要更多信息,我会在看到您的请求后立即提供,谢谢大家的宝贵时间,希望您今天过得愉快。
编辑:请求堆栈跟踪:
at FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal (FreshTinyIoC.FreshTinyIoCContainer+TypeRegistration registration, FreshTinyIoC.NamedParameterOverloads parameters, FreshTinyIoC.ResolveOptions options) [0x000f7] in C:"Here goes the path"
at FreshTinyIoC.FreshTinyIoCContainer.Resolve (System.Type resolveType, System.String name) [0x00000] in C:\"Here goes the path"
at FreshTinyIoC.FreshTinyIoCContainer.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here goes the path"
at FreshMvvm.FreshTinyIOCBuiltIn.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here goes the path"
at FreshMvvm.PageModelCoreMethods.PushPageModelWithPage (Xamarin.Forms.Page page, FreshMvvm.FreshBasePageModel pageModel, System.Object data, System.Boolean modal, System.Boolean animate) [0x00177] in C:"Here goes the path"
at FreshMvvm.PageModelCoreMethods.PushPageModel (FreshMvvm.FreshBasePageModel pageModel, System.Object data, System.Boolean modal, System.Boolean animate) [0x00048] in C:"Here goes the path"
at FreshMvvm.PageModelCoreMethods.PushPageModel[T] (System.Object data, System.Boolean modal, System.Boolean animate) [0x00040] in C:"Here goes the path"
at FirstApp.ViewModels.LogInViewModel.b__5_0 () [0x0003a] in D:\"Here goes the path"
问题是对概念的误解,我认为内容页和导航页是两种不同类型的页面,例如标签页、主详细页、轮播页和内容页。所以我试图不使用下面的代码,认为 FreshNavigationContainer 强迫我使用导航页面而不是内容页面,这是真的但不完全是,因为是的,它强迫你使用导航页面,但你也在使用一个内容页,因为导航页是内容页的属性,所以正如我所说,这都是对概念的误解:
public partial class App : Application
{
public App()
{
InitializeComponent();
var thePage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
MainPage = new FreshNavigationContainer(thePage);
}
}
我没有在问题上这么说,但所有这一切的目的是看不到屏幕顶部的栏,现在我明白了,因为导航页面和内容页面不是2 件不同的事情,您可以在 page.xaml 中使用:
<ContentPage NavigationPage.HasNavigationBar="False">
我试图在按下按钮时使用 MVVM 在我的 xamarin 表单应用程序中推送模式页面。我已经知道如何使用导航堆栈,但不知道如何将内容页面用作模态页面,我尝试了多种方法,尤其是调用 PushPageModel 方法。
这是我尝试过的最后一件事: 查看或页面:
<Label
x:Name="forgottenPasswordLabel"
Text="Forgot password?"
TextColor="LightPink"
FontSize="16"
FontAttributes="Bold"
VerticalOptions="Start"
HorizontalOptions="End"
Margin="25,0,25,25">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ForgotPasswordCommand}"/>
</Label.GestureRecognizers>
</Label>
视图模型class:
public class LogInViewModel : FreshBasePageModel
{
public ICommand ForgotPasswordCommand { get; set; }
public LogInViewModel()
{
}
public override void Init(object initData)
{
ForgotPasswordCommand = new Command (async() =>
{
var newPage = FreshPageModelResolver.ResolvePageModel<ForgottenPasswordViewModel>();
await CoreMethods.PushPageModel<ForgottenPasswordViewModel>(null, false, true);
});
}
}
App.xaml.cs class:
public App()
{
InitializeComponent();
MainPage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
}
此代码给出以下错误:"FreshTinyIoC.TinyIoCResolutionException: 'Resolve failed: IFreshNavigationService"
就是这样,如果您需要更多信息,我会在看到您的请求后立即提供,谢谢大家的宝贵时间,希望您今天过得愉快。
编辑:请求堆栈跟踪:
at FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal (FreshTinyIoC.FreshTinyIoCContainer+TypeRegistration registration, FreshTinyIoC.NamedParameterOverloads parameters, FreshTinyIoC.ResolveOptions options) [0x000f7] in C:"Here goes the path" at FreshTinyIoC.FreshTinyIoCContainer.Resolve (System.Type resolveType, System.String name) [0x00000] in C:\"Here goes the path" at FreshTinyIoC.FreshTinyIoCContainer.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here goes the path" at FreshMvvm.FreshTinyIOCBuiltIn.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here goes the path" at FreshMvvm.PageModelCoreMethods.PushPageModelWithPage (Xamarin.Forms.Page page, FreshMvvm.FreshBasePageModel pageModel, System.Object data, System.Boolean modal, System.Boolean animate) [0x00177] in C:"Here goes the path" at FreshMvvm.PageModelCoreMethods.PushPageModel (FreshMvvm.FreshBasePageModel pageModel, System.Object data, System.Boolean modal, System.Boolean animate) [0x00048] in C:"Here goes the path" at FreshMvvm.PageModelCoreMethods.PushPageModel[T] (System.Object data, System.Boolean modal, System.Boolean animate) [0x00040] in C:"Here goes the path" at FirstApp.ViewModels.LogInViewModel.b__5_0 () [0x0003a] in D:\"Here goes the path"
问题是对概念的误解,我认为内容页和导航页是两种不同类型的页面,例如标签页、主详细页、轮播页和内容页。所以我试图不使用下面的代码,认为 FreshNavigationContainer 强迫我使用导航页面而不是内容页面,这是真的但不完全是,因为是的,它强迫你使用导航页面,但你也在使用一个内容页,因为导航页是内容页的属性,所以正如我所说,这都是对概念的误解:
public partial class App : Application
{
public App()
{
InitializeComponent();
var thePage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
MainPage = new FreshNavigationContainer(thePage);
}
}
我没有在问题上这么说,但所有这一切的目的是看不到屏幕顶部的栏,现在我明白了,因为导航页面和内容页面不是2 件不同的事情,您可以在 page.xaml 中使用:
<ContentPage NavigationPage.HasNavigationBar="False">