Xamarin Forms Labs:调用ViewFactory.CreatePage时出现NullReferenceException

时间:2015-01-04 14:30:15

标签: xamarin ninject xamarin.forms

尝试使用Xamarin.Forms.Labs(v1.2.0)ViewFactory.CreatePage方法时遇到问题。

这是我的共享表单App.cs:

public static Page GetMainPage()
    {
        ViewFactory.Register<JobsView, JobsViewModel>();

        return new NavigationPage(ViewFactory.CreatePage<JobsViewModel>());
    }

我的JobsViewModel的顶部:

[ViewType(typeof(JobsView))]
public class JobsViewModel : Xamarin.Forms.Labs.Mvvm.ViewModel
{

我的观点:

public partial class JobsView : Xamarin.Forms.Labs.Mvvm.BaseView
{
    public JobsView()
    {
        InitializeComponent();
        BindingContext = new JobsViewModel();
    }

这是我的Windows Phone 8.0项目的App.xaml.cs中的IoC设置:

var app = new XFormsAppWP();
            app.Init(this);

var resolverContainer = new NinjectContainer();
        resolverContainer.Register<IDevice>(t => WindowsPhoneDevice.CurrentDevice)
            .Register<IDisplay>(t => t.Resolve<IDevice>().Display)
            .Register<IDependencyContainer>(t => resolverContainer)
            .Register<IXFormsApp>(app);

Resolver.SetResolver(resolverContainer.GetResolver());

调用ViewFactory.CreatePage<JobsViewModel>()时,出现以下错误:

    System.NullReferenceException: Object reference not set to an instance of an object.
   at Ninject.Planning.Bindings.BindingConfiguration.GetProvider(IContext context)
   at Ninject.Planning.Bindings.Binding.GetProvider(IContext context)
   at Ninject.Infrastructure.Introspection.FormatExtensionsEx.Format(IBinding binding, IContext context)
   at Ninject.KernelBase.<Resolve>b__a(<>f__AnonymousType0`2 <>h__TransparentIdentifier8)
   at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings)
   at Ninject.KernelBase.Resolve(IRequest request)
   at Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique)
   at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
   at Xamarin.Forms.Labs.Services.Ninject.NinjectResolver.Resolve[T]()
   at Xamarin.Forms.Labs.Services.Resolver.Resolve[T]()
   at Xamarin.Forms.Labs.Mvvm.ViewFactory.CreatePage[TViewModel](Action`2 initialiser)
   at SharedForms.App.GetMainPage()
   at Windows.Phone.MainPage..ctor()

有关如何修复/调试的任何帮助进一步表示赞赏。

0 个答案:

没有答案