samedi 18 juin 2016

Strange behavior on Android Checkbox with MvvmCross

I have an MvxListView defined this way:

<Mvx.MvxListView
                        android:background="@drawable/back"
                        android:layout_width="match_parent"
                        android:layout_height="175dp"
                        local:MvxBind="ItemsSource Tipos"
                        android:choiceMode="singleChoice"
                        android:fadeScrollbars="false"
                        local:MvxItemTemplate="@layout/checkboxcaptionvalue" />

The @layout/checkboxcaptionvalue is a simple template that has only a checkbox with some bindings:

<CheckBox
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto/Capta.Mobile.Vendas"
    local:MvxBind="Checked Selected; Text Caption"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

The Tipos property is an array of DummyBool:

private DummyBool[] _tipos;
public DummyBool[] Tipos
{
    get { return _tipos; }
    set { _tipos = value; RaisePropertyChanged(); }
}

And that's the DummyBool class:

public class DummyBool
{
    public string Caption { get; set; }
    private bool _selected;

    public bool Selected
    {
        get { return _selected; }
        set { _selected = value; }
    }

}

I'm facing a very strange issue: every time I set the Tipos property, the Selected property of it's itens change to false.

I've tried to remove the RaisePropertyChanged() from the set of the Tipos property, and this way, the Selected property does not change, but also my UI is not updated, so I can't see the checkboxes inside the MvxListView. I also created a Button that has it's click binded to the following command:

public IMvxCommand RaiseTiposChanged
{
    get
    {
        return new MvxCommand(() =>
        {
            RaisePropertyChanged(() => Tipos);
        });
    }
}

Calling it also sets the Selected property to false.

Edit:

I'm setting the Tipos property this way:

Tipos = _pendencias.GroupBy(p => p.Tipo)
                      .Select(g => new DummyBool { Caption = g.Key, Selected = true })
                      .ToArray();

_pendencias is a simple List<T>.

Aucun commentaire:

Enregistrer un commentaire