c# - How to navigate through modal pages in Xamarin.Forms using Fresh.MVVM
问题描述
I was trying to push a modal page in my xamarin forms app using MVVM when pressing a button. I already know how to use navigation stacks, but no idea how to do it with content pages as modal pages, I have tried multiple things, especially, calling the PushPageModel method.
This is the last thing I have tried: View or Page:
<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>
ViewModel 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>();
}
This code gives the following error: "FreshTinyIoC.TinyIoCResolutionException: 'Resolve failed: IFreshNavigationService"
And that is all, if you need more information I will provide it as soon as I see your request, thank you all for your time, hope you have a great day.
Edit: Stack trace requested:
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"
解决方案
The problem was a misunderstanding of concepts, I thought that a content page and a navigation page were two different types of pages, like a tabbed page, master detailed page, carousel page, and content page. So I was trying not to use the following code thinking that FreshNavigationContainer forced me to use a navigation page and not a content page, which is true but not completely, because yes, it forces you to use a navigation page, but you are also using a content page, since navigation page is a property of content page, so as I said it was all a misunderstanding of concepts :
public partial class App : Application
{
public App()
{
InitializeComponent();
var thePage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
MainPage = new FreshNavigationContainer(thePage);
}
}
I didn't say this on the question, but the purpose of all of this was to not see a bar at the top of the screen, which now I understand that because a navigation page and a content page are not 2 different things, you can do it in the page.xaml with:
<ContentPage NavigationPage.HasNavigationBar="False">
推荐阅读
- sql - 如何在 SQL (Postgres) 中查找子字符串
- javascript - Leaflet.Draw 多边形的坐标
- firebase - 未经身份验证的最终用户正在调用 Firebase HTTPS 可调用函数
- active-directory - 我可以拥有 2 个具有相同域扩展名的独立 Active Directory 林吗?
- python - Anaconda 环境不会激活
- java - 如何检查用户是否在不和谐中扮演角色
- json - 如何在 Python 中使用循环从 JSON 中提取元素?
- java - java中类调用中无法访问的语句
- mysql - 如何使 MYSQL GROUP_CONCAT 结果不同并按出现次数排序
- kubernetes - gke:入口未转发到 NodePort 服务:
/healthz
在此服务器上未找到