Search code examples
androidandroid-layoutxamarinmvvmcross

MvxBind on FloatingActionButton


I use the official FloatingActionButton for Android. My problem is that the binding doesn't work. In my case a click event (local:MvxBind="Click GoToSharePageCommand").

When listening for the click in the code behind all works fine.

Does anyone know what could cause this? Could it be e a namespacing conflict?

Here's my xml

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/ic_action_add"
    local:borderWidth="0dp"
    local:elevation="4dp"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    local:layout_anchor="@id/mainDrawerLayout"
    local:layout_anchorGravity="bottom|right|end"
    local:MvxBind="Click GoToSharePageCommand" />

EDIT:

This part of Martijn's solution did it for me:

public class Setup : MvxAndroidSetup
{
    public Setup(Context applicationContext)
        : base(applicationContext)
    {
    }

    protected override IList<Assembly> AndroidViewAssemblies
    {
        get
        {
            var assemblies = base.AndroidViewAssemblies;
            assemblies.Add(typeof(Android.Support.Design.Widget.FloatingActionButton).Assembly);
            return assemblies;
        }
    }
}

Solution

  • I've created a gist to show how to implement this in MvvmCross: https://gist.github.com/martijn00/671b6fec9b22e842d2c4