MvvmCross - MvxBind:Warning 无法为 -empty- 的绑定 Hello 创建目标绑定

MvvmCross - MvxBind:Warning Failed to create target binding for binding Hello for -empty-

我刚刚开始我的第一个 Xamarin 应用程序,并且已经设置了与新解决方案的默认配置非常相似的设置,更改非常少。

应用程序可以正常编译并部署到虚拟设备。

MvxBindingAttributes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="MvxBinding">
    <attr name="MvxBind" format="string"/>
    <attr name="MvxLang" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxControl">
    <attr name="MvxTemplate" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxListView">
    <attr name="MvxItemTemplate" format="string"/>
    <attr name="MvxDropDownItemTemplate" format="string"/>
  </declare-styleable>
  <item type="id" name="MvxBindingTagUnique"/>
  <declare-styleable name="MvxImageView">
    <attr name="MvxSource" format="string"/>
  </declare-styleable>
</resources>

HomeViewModel.cs

public class HomeViewModel : MvxViewModel
{
    /// <summary>
    /// The _hello.
    /// </summary>
    private string _hello = "Hello MvvmCross";

    /// <summary>
    /// Gets or sets the hello.
    /// </summary>
    public string Hello
    {
        get
        {
            return _hello;
        }

        set
        {
            _hello = value;
            RaisePropertyChanged(() => Hello);
        }
    }
}

App.cs

public class App : Cirrious.MvvmCross.ViewModels.MvxApplication
{
    /// <summary>
    /// The initialize.
    /// </summary>
    public override void Initialize()
    {
        CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsLazySingleton();
        RegisterAppStart<HomeViewModel>();
    }
}

HomeView.cs

[Activity(Label = "View for HomeViewModel")]
public class HomeView : MvxActivity
{
    /// <summary> The on create. </summary>
    /// <param name="bundle"> The bundle. </param>
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.HomeView);
    }
}

HomeView.axml

<?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 Hello" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Hello" />
</LinearLayout>

当我在设备上 运行 时,Hello MvvmCross 文本按预期显示,但在输出中 window 我看到这个错误:

MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-
[0:] MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-
05-13 12:56:37.654 I/mono-stdout(  683): MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-

如果我关闭虚拟设备上的应用程序然后再次启动它,我得到:

MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-
[0:] MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-
05-13 12:58:06.802 I/mono-stdout(  683): MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-

我似乎找不到比去年更新的关于此问题的任何信息。

为什么它报告绑定失败但仍按预期绑定?还有为什么警告号 (8.57 / 9.69) 会改变但有相同的错误信息?

解决方案中还包含默认的 LinkerPleaseInclude.cs 文件,所以我现在对此有点困惑。

您需要设置要在 Activity 中使用的视图模型。

更改此行: public class HomeView : MvxActivity 至:public class HomeView : MvxActivity<HomeViewModel>

原来我的绑定声明之一不正确:

HomeView.axml

<TextView
    ...
    local:MvxBind="Hello" />

应该是:

<TextView
    ...
    local:MvxBind="Text Hello" />

缺少类型 Text