1
votes

In a simple Monodroid/Mvvmcross project my bindings for a switch do not trigger and I have to use a workaround to complete the behavior. I heard from a college, but am unable to find confirmation that Monodroid doesn't support switches properly yet. Thus I am wondering if this carries to Mvvmcross bindings.

Is MvvmCross unable to bind to a Switch compound button?

Code

SettingsView.axml

<FrameLayout [...]>
    <ScrollView [...]>
        <LinearLayout [...]>
            <Switch
                android:id="@+id/userSettingsView_Button"
                local:MvxBind="Checked ButtonChecked" />
        </LinearLayout>
    </ScrollView>
</FFrameLayout>

SettingsViewModel.cs

public class SettingsViewModel : MvxViewModel {
    [...]

    public bool ButtonChecked {
        get [...] set{[...]; RaisePropertyChanged(() => ButtonChecked);}
    }
}

I have a version that the axml uses a checked button for legacy android version and the binding (/s/Switch/ToggleButton) works fine. This setup I get a MvxBind error: 6.07 View type not found - Switch.

2

2 Answers

0
votes

CompoundButton binding for Checked with CheckedChange is implemented via https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/Target/MvxCompoundButtonCheckedTargetBinding.cs and this is in place for any class inheriting from CompoundButton

If you find an issue, then reproducing it and logging it with either Xamarin (for a Xamarin issue) or MvvmCross (for an MvvmCross issue) - but I'm not sure anyone will be able to assist without a sample which reproduces the problem(s).

0
votes

Be sure that you added the Switch in your LinkerPleaseInclude.cs. Maybe it will be stripped out during binding..

public void Include(Switch cb)
{
  cb.CheckedChange += (sender, args) => cb.Checked = !cb.Checked;
}