【问题标题】:How to navigate through modal pages in Xamarin.Forms using Fresh.MVVM如何使用 Fresh.MVVM 在 Xamarin.Forms 中导航模式页面
【发布时间】: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


【解决方案1】:

问题是对概念的误解,我认为内容页和导航页是两种不同类型的页面,如标签页、主详细页、轮播页和内容页。所以我试图不使用下面的代码,认为 FreshNavigationContainer 强迫我使用导航页面而不是内容页面,这是真的但不完全,因为是的,它迫使你使用导航页面,但你也在使用一个内容页面,因为导航页面是内容页面的一个属性,所以正如我所说的,这都是对概念的误解:

public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            var thePage = FreshPageModelResolver.ResolvePageModel<LogInViewModel>();
            MainPage = new FreshNavigationContainer(thePage);
        }
}

我没有在问题上这么说,但所有这些的目的是在屏幕顶部看不到一个栏,现在我明白了,因为导航页面和内容页面不是两个不同的事情,你可以在 page.xaml 中使用:

<ContentPage NavigationPage.HasNavigationBar="False">

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多