【发布时间】:2020-05-24 08:18:08
【问题描述】:
我试图在按下按钮时使用 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>
ViewModel 类:
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 类:
public App()
{
InitializeComponent();
MainPage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
}
此代码给出以下错误:“FreshTinyIoC.TinyIoCResolutionException: 'Resolve failed: IFreshNavigationService”
仅此而已,如果您需要更多信息,我会在看到您的请求后立即提供,感谢大家的宝贵时间,希望您度过愉快的一天。
编辑:请求堆栈跟踪:
在 FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal (FreshTinyIoC.FreshTinyIoCContainer+TypeRegistration 注册,FreshTinyIoC.NamedParameterOverloads 参数,FreshTinyIoC.ResolveOptions 选项) [0x000f7] in C:"Here go the path" 在 FreshTinyIoC.FreshTinyIoCContainer.Resolve (System.Type resolveType, System.String name) [0x00000] in C:\"Here go the path" 在 FreshTinyIoC.FreshTinyIoCContainer.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here go the path" 在 FreshMvvm.FreshTinyIOCBuiltIn.Resolve[ResolveType] (System.String name) [0x00000] in C:"Here go the path" 在 FreshMvvm.PageModelCoreMethods.PushPageModelWithPage(Xamarin.Forms.Page 页面,FreshMvvm.FreshBasePageModel pageModel,System.Object 数据,System.Boolean 模态,System.Boolean animate)[0x00177] 在 C 中:“这里是路径” 在 FreshMvvm.PageModelCoreMethods.PushPageModel (FreshMvvm.FreshBasePageModel pageModel, System.Object data, System.Boolean modal, System.Boolean animate) [0x00048] in C:"Here go the path" 在 FreshMvvm.PageModelCoreMethods.PushPageModel[T] (System.Object data, System.Boolean modal, System.Boolean animate) [0x00040] in C:"Here go the path" 在 FirstApp.ViewModels.LogInViewModel.b__5_0 () [0x0003a] in D:\"Here go the path"
【问题讨论】:
-
根据我对异常的了解,您的
ForgottenPasswordViewModel或视图中存在导致此问题的内容,可能会引发异常,或者您没有遵循文件夹结构或 @ 987654325@ 现在为了让我们更容易理解这一点,您必须在此处添加此异常的 Stracktrace! -
@FreakyAli 如何获取异常的堆栈跟踪
-
在抛出异常时在 catch 块中添加 try-catch 块,异常对象包含您的 StackTrace!如果您有例外情况,这是开始查找问题的最佳地点!
-
@FreakyAli 我用 StackTrace 更新了这个问题!
-
找不到 IFreshNavigationService 的实例,所以我认为您没有正确初始化 FreshMVVM。在某些时候,需要告诉 TinyIOC 如何实例化导航服务。我怀疑它是否也适用于非模态页面。
标签: c# xamarin xamarin.forms freshmvvm