【发布时间】:2016-04-30 13:59:35
【问题描述】:
我使用 Xamarin 和 MvvmCross 创建了一个 Android 应用程序。 我想将一些视图(文本、编辑文本、按钮)绑定到我的 ViewModel。到目前为止没有什么奇怪的。但是我的绑定不适用……当我使用键入的 FindViewById 时,我没有得到跟踪的错误,但绑定不适用。
当我运行应用程序时,我有以下跟踪:
MvxBind:Error: Empty binding target passed to MvxTargetBindingFactoryRegistry
MvxBind:Warning: Failed to create target binding for binding for TextProperty
我对@987654323@ void 的覆盖是:
SetContentView(Resource.Layout.Reference);
var referenceTextView = FindViewById(Resource.Id.referenceEditView); // untyped FindViewById
var siteTextView = FindViewById<TextView>(Resource.Id.siteTextView); // typed FindViewById<T>
//var goButton = FindViewById<Button>(Resource.Id.goButton);
var bindingsSet = this.CreateBindingSet<ReferenceView, ReferenceViewModel>();
bindingsSet.Bind(referenceTextView).To(vm => vm.Reference).Mode(MvxBindingMode.TwoWay);
bindingsSet.Bind(siteTextView).To(vm => vm.Site);
//bindingsSet.Bind(goButton).To(vm => vm.GoCommand);
bindingsSet.Apply();
base.OnCreate(bundle);
我已经尝试在 AXML 中做:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/siteTextView"
android:text="####"
local:MvxBind="Text Site"
android:gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/referenceTextView"
android:hint="Numéro de dossier"
local:MvxBind="Text Reference" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accéder"
android:id="@+id/goButton"
local:MvxBind="Click GoCommand" />
我的属性的 getter 和 setter 使用 RaiseAndSetIfChanged 方法:
private string _reference;
public string Reference
{
get { return _reference; }
set { this.RaiseAndSetIfChanged(ref _reference, value, () => Reference); }
}
我的 LinkerPleaseInclude 课程与 LinkerPleaseInclude 原始课程相同。
我的设置继承自 MvxAndroidSetup 类
在其他 ViewModel 上,绑定应用正确。
【问题讨论】:
标签: c# android xamarin mvvmcross