簡體   English   中英

Android中的MVVMCross交叉綁定不起作用

[英]MVVMCross binding in Android not work

我是MVVMCross的新手,我在這里重寫了演示代碼:,更改不多,但是綁定的東西不起作用,它應該顯示錯誤日志以進行調試。 我也閱讀了命名約定這是我的viewmodel類

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM