I have an MvvmCross MvxSpinner
binding in Android. The user selects a value and that gets reflected in my property MealTypeSelected
.
<MvxSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource MealTypeList;SelectedItem MealTypeSelected, Mode=TwoWay" />
The spinner is to allow the user to select the meal type (breakfast, lunch, dinner, etc). The meal type is represented by an Enum called MealType
.
public enum MealType {Unspecified, Breakfast, Lunch, Dinner, Snack};
I want to make it easier on the user by initializing the spinner to a value based on the time of day when the ViewModel
is shown. So if the page is loaded at noon, I'll guess that the selection should be "Lunch" for example.
The problem is, I have tried setting the MealTypeSelected
property in the ViewModel
at different locations of the life cycle: constructor, Init
, and Start
. But regardless of what I do, when the View loads, it changes the selection back to the default value of the Enum, which is the value "Unspecified".
Is there a way around this behavior and have the MvxSpinner
initialized to specific value?
Try to add this to your "Setup.cs" file. I had the same struggle, and this worked for me. Cant remember where i found the solution the first time.
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
MvxAppCompatSetupHelper.FillTargetFactories(registry);
base.FillTargetFactories(registry);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With