Visual Studio无法识别MvxFragment的BindingInflate函数

时间:2014-02-20 17:09:32

标签: c# android xamarin.android xamarin mvvmcross

我有以下课程:

using Cirrious.MvvmCross.Binding.BindingContext;
using Cirrious.MvvmCross.Droid.Views;
using Cirrious.MvvmCross.Droid.Fragging;
using Cirrious.MvvmCross.Droid.Fragging.Fragments;

public class DifficultyItemFragment : MvxFragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var ignored = base.OnCreateView(inflater, container, savedInstanceState);
        return this.BindingInflate(Resource.Layout.DifficultyItemFragment, null);
    }
}

我收到以下错误:

 Error  8   ...'QuickShift.Android.Views.DifficultyItemFragment' does not contain a definition for 'BindingInflate' and no extension method 'BindingInflate' accepting a first argument of type 'QuickShift.Android.Views.DifficultyItemFragment' could be found (are you missing a using directive or an assembly reference?)

我查看了MvvmCross源代码,BindingInflate确实存在于BindingContext命名空间中。

我错过了什么吗?我引用了所有必需的库,包括Xamarin.Android.Support.v4

enter image description here

更新

我在VS 2013中创建了一个示例项目来说明问题。您会注意到在Fragment1.cs中存在同样的问题:

Sample app

1 个答案:

答案 0 :(得分:6)

BindingInflate实际上是一种扩展方法。您需要导入正确的命名空间(对于版本3.5.x)。

using Cirrious.MvvmCross.Binding.Droid.BindingContext;

对于版本4.x,MvvmCross重新组织了名称空间。正确的导入是:

using MvvmCross.Binding.Droid.BindingContext;

编辑:添加版本信息以回答并包含v4.x的更新名称空间