androidxamarinmvvmcrossandroid-mvvmmvxbind

Bind multiple values to one control Xamarin.Android MVVMCross MVX


I like to bind 2 properties from my ViewModel into my EditText control via MVX I've tried the code below but the compiler does not approve the second local:mvxBind.

<EditText
            android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
            android:layout_width="match_parent"
            android:layout_height="110dp"
            android:gravity="top"
            local:MvxBind="MaxLength Config.Field.GetMaxLength"
            local:MvxBind="Text Config.Field.TextValue"
            android:layout_marginBottom="0.0dp"
            android:id="@+id/txtValue"/>

My ViewModel has a config object, and the config object has a field object. When I just bind 1 property. In case of the Text property, it works fine. In case of the MaxLenght property, the value is ignored

Anyone any ideas?

update: I found the method to bind multiple properties:

local:MvxBind="MaxLength Config.Field.GetMaxLength; Text Config.Field.TextValue"

The Text binding is oK... I can see the GetMaxLength properties is Get on a break point in my ViewModel... But still ignored in the EditText control.

I wonder if the EditText property MaxLength can be bind with MVX. If so? How?


Solution

  • I did a workaround in my View and set the MaxLength via the EditView.filters like this:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                var view = base.OnCreateView(inflater, container, savedInstanceState);
                
                // FIX for max length on Edit Text
                if(ViewModel.Config.Field.MaxLength != null)
                {
                    int maxLength = (int)ViewModel.Config.Field.MaxLength;
                    var editText = view.FindViewById<EditText>(Resource.Id.txtValue);
                    editText.SetFilters(new Android.Text.IInputFilter[] { new Android.Text.InputFilterLengthFilter(maxLength) });
                }
    
                return view;
            }
    

    If there is another way to do via MVX. Please let us know