在带有棱镜mvvm视图模型的xamarin形式的xaml中包括xaml。无法解析INavigationService

吉米1988

我想在所选页面中包含一个后退按钮。由于某种原因,我将其称为“面包屑”,请假定其名为“ BackButton” :)。

问题是导航服务无法在ioc中获得通过。

以下是我遇到的以下代码:

XAML主页-注意local:BreadcrumbControl

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="Test.Views.MainPage"
             xmlns:local="clr-namespace:Test.Views">

    <StackLayout>
        <local:BreadcrumbControl x:Name="Breadcrumb" />
    </Stacklayout>
<ContentPage>

面包屑控制XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="Test.Views.BreadcrumbControl">

    <Button Text="Back" Command="{Binding NavigateCommand}" CommandParameter="NavigationPage/ManageFoodGroupsPage" />

</ContentView>

面包屑页面视图模型

public class BreadcrumbControlViewModel : BindableBase
{
    INavigationService navigationService;

    public DelegateCommand<string> NavigateCommand { get; set; }

    // If i uncomment the navigationservice the following error occurs (*)
    public BreadcrumbControlViewModel(/*INavigationService navigationService*/)
    {
        this.navigationService = navigationService;
        NavigateCommand = new DelegateCommand<string>(Navigate);
    }

    private void Navigate(string name)
    {
        navigationService.GoBackAsync();
    }
}

(*)

Microsoft.Practices.Unity.dll中发生类型为“ Microsoft.Practices.Unity.ResolutionFailedException”的异常,但未在用户代码中处理

附加信息:依赖关系的解析失败,类型=“ Test.ViewModels.BreadcrumbControlViewModel”,名称=“(none)”。

在以下期间发生异常:解析构造函数Test.ViewModels.BreadcrumbControlViewModel(Prism.Navigation.INavigationService navigationService)的参数“ navigationService”。

异常是:NullReferenceException-对象引用未设置为对象的实例。


在发生异常时,容器为:

解决Test.ViewModels.BreadcrumbControlViewModel,(无)

解析构造函数Test.ViewModels.BreadcrumbControlViewModel(Prism.Navigation.INavigationService navigationService)的参数“ navigationService”

App.cs容器/解析器注册

ViewModelLocationProvider.Register<BreadcrumbControl, BreadcrumbControlViewModel>();

Container.RegisterTypeForNavigation<MainPage>();

如何在Xamarin Forms Prism MVVM应用程序中包含常见的后退按钮样式的东西(由视图模型驱动)。

54

由于Xamarin.Forms(基于页面)中导航的性质,INavigationService仅适用于属于Page类型的ViewModel。它必须是一个页面,否则,您将无法导航。如果必须在此ContentView的VM中具有INavigationService,则必须在容器中注册INavigationService,但它可能无法正常运行,因为它将在Application.Current.MainPage(而不是正确的Page)上运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Xamarin.Forms(带有XAML)中时切换视图

来自分类Dev

xaml无法识别模型的属性(WPF MVVM)

来自分类Dev

无法在Xamarin XAML中引用本机Android视图

来自分类Dev

与XAML视图模型接口

来自分类Dev

Xamarin Forms - 在内容视图的视图模型中访问 Prism INavigationService

来自分类Dev

无法解析XAML / XML

来自分类Dev

代码无法识别xaml中的名称视图(Xamarin Forms Visual Studio 2015)

来自分类Dev

如何在Xamarin形式的XAML中绑定类属性

来自分类Dev

xaml ResourceDictionary中预期用于Xamarin形式的标识符

来自分类Dev

如何在Xamarin形式的XAML中绑定类属性

来自分类Dev

Xamarin中XAML的BindingProxy

来自分类Dev

带有ReactiveUI,Xamarin Forms和XAML的“ Hello World”

来自分类Dev

带有ReactiveUI,Xamarin Forms和XAML的“ Hello World”

来自分类Dev

带有分层视图模型的Unity的MVVM依赖项注入

来自分类Dev

棱镜6的XAML命名空间

来自分类Dev

棱镜Xamarin形成Mvvm错误

来自分类Dev

带有参数的XAML DataTemplate

来自分类Dev

已将DataContext设置为视图模型时在XAML中引用视图成员

来自分类Dev

Xamarin在Xaml中形成OnPlatform

来自分类Dev

XAML中的Xamarin Forms TableView

来自分类Dev

UWP 10 (xaml) - MVVM - 带有嵌套 Observable 集合的列表框

来自分类Dev

汉堡菜单棱镜xamarin形式?

来自分类Dev

带有Xaml.Behaviors.Wpf的Caliburn Micro,无法在事件触发器中包含动作消息

来自分类Dev

我无法提供带有匕首的视图模型

来自分类Dev

Java:无法在Spring MVC中解析带有名称的视图

来自分类Dev

从视图(xaml.cs)调用视图模型方法

来自分类Dev

重构视图模型和视图之间的xaml映射

来自分类Dev

从MVVM中的视图模型关闭视图

来自分类Dev

带棱镜的 MVVM 中的 DispatcherTimer?

Related 相关文章

热门标签

归档