Initial value of MvxSpinner

I have an MvvmCross binding MvxSpinnerin Android. The user selects a value and 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 rotator allows the user to select the type of dish (breakfast, lunch, dinner, etc.). The type of food represented by Enum, called MealType.

public enum MealType {Unspecified, Breakfast, Lunch, Dinner, Snack};

I want to make it easier for the user by initializing the counter to a value based on the time of day when it is displayed ViewModel. Therefore, if the page is loaded at noon, I think that the choice should be, for example, “Lunch”.

The problem is that I tried to set the property MealTypeSelectedin ViewModelin different places of the life cycle: constructor Initand Start. But no matter what I do, when the View loads, it changes the selection back to the default Enum, which is the "Unspecified" value.

Is there a way around this behavior and initialize MvxSpinnerfor a specific value?

+4
source share
3 answers

pnavk , , . , -, , . , . , , , , .

0

"Setup.cs". , . , .

    protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
    {
        MvxAppCompatSetupHelper.FillTargetFactories(registry);
        base.FillTargetFactories(registry);
    }
+1

SelectedItem MvxSpinner ViewModel, ViewModel.

Equals , , .

public override bool Equals(object obj)
{
    return this.Id == (obj as MyType)?.Id;
}

, , , , , .

+1

All Articles