【问题标题】:MVVMCross binding in Android not workAndroid中的MVVMCross绑定不起作用
【发布时间】:2017-09-25 08:44:36
【问题描述】:

我是 MVVMCross 的新手,我重写了 here 中的演示代码:,没有改变太多,但是绑定的东西不起作用,它应该显示错误日志以进行调试。我还阅读了命名约定 这是我的视图模型类

 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>

【问题讨论】:

    标签: android mvvm mvvmcross


    【解决方案1】:

    只需更改这些代码行即可:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      相关资源
      最近更新 更多