2
votes

I'm having a tough time getting a basic MvvmCross Android example working where the BackgroundColor of the RelativeLayout is bound to the ViewModel.

The app runs, some text appears, and I'm expecting my background to turn Yellow. The background color, however, remains unchanged.

I have included the Hot Tuna starter pack in both my Core and Droid projects as well as the MvvmCross - Color Plugin. My Droid project was automatically given ColorPluginBootstrap.cs

Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    local:MvxBind="BackgroundColor NativeColor(BackgroundColor)">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="20sp"
            android:gravity="center"
            android:text="Text to make sure the layout inflates" />
</RelativeLayout>

ViewModel

public class ViewModel : MvxViewModel
{
    RGBAColorConverter _rgbaConverter;
    public ViewModel()
    {
        var color = "#ffedff00";
        _rgbaConverter = new RGBAColorConverter();
        BackgroundColor = _rgbaConverter.Convert(color);
    }

    private MvxColor _backgroundColor;
    public MvxColor BackgroundColor
    {
        get { return _backgroundColor; }
        set
        {
            _backgroundColor = value;
            RaisePropertyChanged(() => BackgroundColor);
        }
    }
}

Binding works - I've tried making other ViewModel properties that were string to do simple text binding. All of that seems just fine.

I've placed debugging break points on the getter of the BackgroundColor ViewModel property and I can see the MvxColor as expected.

What am I missing for my color binding scenario?

  • I haven't done anything extra in the Setup.cs
  • I haven't created any other wiring up classes in my Droid project
  • I haven't created any Android-specific color converter implementations
1
NativeColor(BackgroundColor) , this is yours own MvxConverter or any you have used any plugin for this ? If yes, please mention link of pluginAjay Sharma

1 Answers

5
votes

I've just written a test app and it seems to work for me - using 3.0.14 nuget binaries.

Also, the ValueConverters test app seemed to work OK - https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/ValueConversion

Looking at your sample, the only thing I can think of is that maybe you are only testing transparent colours (RGBA #ffedff00 has Alpha=0)

If that isn't it, can you post more - perhaps a full sample somewhere?