android - Android中的MVVMCross绑定(bind)不起作用

标签 android mvvm mvvmcross

我是 MVVMCross 的新手,我重写了 here 中的演示代码: , 没怎么改,但是绑定(bind)的东西不行,应该显示错误日志以便调试。我还阅读了命名约定
这是我的 View 模型类

 public class FirstViewModel:MvxViewModel
{
    private string _firstName;
    private string _lastName;

    public string FirstName {
        set { SetProperty(ref _firstName, value); RaisePropertyChanged(() => FirstName); }
        get { return _firstName; }
    }

    public string LastName {
        set { SetProperty(ref _lastName, value); RaisePropertyChanged(() => LastName); }
        get { return _lastName; }
    }

    public string FullName {
        get { return string.Format("{0} {1}", _firstName, _lastName); }
    } 
}

看法:
public class FirstView : MvxActivity<FirstViewModel>
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.FirstView);
    }
}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="40dp"
    local:MvxBind="Text FirstName" />
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="40dp"
    local:MvxBind="Text LastName" />
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="40dp"
    local:MvxBind="Text FullName" />
</LinearLayout>

最佳答案

只需更改这些代码行,它就可以工作:

RaisePropertyChanged(() => FullName
RaisePropertyChanged(() => FullName

关于android - Android中的MVVMCross绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46401022/

相关文章:

java - 注册为音乐播放器并播放歌曲

c# - 另一个未更新的 MVVM 可见性属性

android - 在 MxvFrameControl 中查找 View

MvvmCross:如何绑定(bind)到 UIBarButtonItem 的可见性?

java - 将当前 Activity 实例传递给方法

Android Studio 与 GitHub 的集成无法上传除 MainActivity.java 之外的项目文件

javascript - 一个具有多个模板的 VueJS 组件

android - 无法在Android Studio中同步gradle 3.1项目:

c# - 使用 Fody [ImplementPropertyChanged] 时出错