我可以使用MvvmCross以编程方式绑定到单个记录

时间:2017-06-14 20:57:06

标签: c# xamarin.android mvvmcross

我有一个应用程序,我有两个垂直的线性布局,我想在其中放置可编辑的行。我正在尝试使用MvvmCross Fluent Binding将每个记录绑定到正确的视图。

public class SurveyView : MvxActivity
{
    SurveyViewModel vm;
    LinearLayout ItemsView;
    LinearLayout CategoryView;


    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here
    }

    protected override void OnViewModelSet()
    {
        base.OnViewModelSet();

        this.SetContentView(Resource.Layout.SurveyView);

        vm = (SurveyViewModel)this.ViewModel;

        ItemsView = FindViewById<LinearLayout>(Resource.Id.lvItems);
        CategoryView = FindViewById<LinearLayout>(Resource.Id.lvCategories);

        vm.PropertyChanged += vm_PropertyChanged;

        this.ActionBar.Title = "Survey - " + vm.ShipperName;

        vm.LoadData();
    }

    private void vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        switch (e.PropertyName)
        {
            case "Items":
                LoadItems();
                break;
            case "Categories":
                LoadCategories();
                break;
        }
    }

    private void LoadCategories()
    {
        CategoryView.RemoveAllViews();
        foreach (ShipmentSurveyCategory Item in vm.Categories)
        {
            var view = LayoutInflater.Inflate(Resource.Layout.SurveyCategoryItem, null);

            var set = this.CreateBindingSet<View, ShipmentSurveyCategory>();

            TextView tv = view.FindViewById<TextView>(Resource.Id.txtName);
            set.Bind(tv).For(v => v.Text).To(i => i.Name);

            EditText et = view.FindViewById<EditText>(Resource.Id.txtWeight);
            set.Bind(et).For(v => v.Text).To(i => i.Cubes).WithConversion("FloatToStringConverter");

            set.Apply();
        }
     }
  }

我收到了错误     var set = this.CreateBindingSet();

是哪个     错误CS1929'ReviewView'不包含'CreateBindingSet'的定义,并且最佳扩展方法重载'MvxBindingContextOwnerExtensions.CreateBindingSet(View)'需要“View”类型的接收器 它不喜欢“这个”。 ShipmentSurveyCategory对象确实实现了INotifyPropertyChanged。

我可以做我想做的事吗?

0 个答案:

没有答案