Jammer
Jammer

Reputation: 10208

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

I'm just starting my first Xamarin application and have gotten things setup pretty much as the default configuration of a new solution with very minimal changes.

The application compiles fine and deploys to the Virtual Device fine as well.

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>

When I run this on the device the Hello MvvmCross text is displayed as expected but in the output window I see this error:

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-

If I close the application on the virtual device and then launch it again I get:

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-

I can't seem to find anything about this problem more recent than last year.

Why is it reporting a binding failure and yet binding as expected? Also why would the warning number (8.57 / 9.69) change but have the same error message?

I also have the default LinkerPleaseInclude.cs file included in the solution so I'm a little confused by this at the moment.

Upvotes: 1

Views: 1369

Answers (2)

Jammer
Jammer

Reputation: 10208

Turns out one of my binding declarations was incorrect:

HomeView.axml

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

Should be:

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

The type Text was missing.

Upvotes: 2

Martijn00
Martijn00

Reputation: 3559

You need to set the viewmodel to use in your Activity.

Change this line: public class HomeView : MvxActivity to: public class HomeView : MvxActivity<HomeViewModel>

Upvotes: 0

Related Questions