【发布时间】:2017-07-18 14:02:21
【问题描述】:
我的 ViewModel 中有自定义对象。
public MyObject PropertyName
{
get { return _propertyName; }
set
{
_propertyName = value;
RaisePropertyChanged(() => PropertyName);
}
}
我只想将其成员之一绑定到我的机器人视图中的 textview。找到这个链接: Bind data of custom object to TextView in MvvmCross 我正在这样做。 local:MvxBind = "Text Myobject.ItsMember"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="LabelCaption" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@android:color/white"
local:MvxBind="Text Myobject.ItsMember" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
检查了大小写等,但绑定不起作用,我看不到屏幕上出现的字符串值,而我可以在调试窗口中打印它。 任何线索我可能会出错?
【问题讨论】:
-
你在哪里夸大这个视图?
-
[Activity(Label = "MyView")] public class MyView : MvxActivity { protected override void OnViewModelSet() { SetContentView(Resource.Layout.MyView); } }
-
而
Myobject是您的 ViewModel 中的属性名称? -
MyObject 是类型。我使用属性名称绑定它 - 像这样 - local:MvxBind="Text PropertyName.Member"
-
您不能在 MyObject 中绑定成员变量,它们必须是属性。
标签: xamarin xamarin.android mvvmcross