Important note: This used to work on MVVM Cross V3.5 but after upgrading to V6.4.2 it stopped working.
In project which extensively uses MVVM Cross there is custom textview.
<custom.HeaderTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marg_top"
android:layout_marginBottom="@dimen/marg_top"
android:gravity="center"
local:MvxBind="Text SearchCriteria"
android:layout_gravity="center_horizontal"
android:textAllCaps="true" />
The local:MvxBind="Text SearchCriteria"
points to the view model which does indeed return text:
public string SearchCriteria => Resource.SearchCriteria;
And the string exists in resources:
public static string SearchCriteria {
get {
return ResourceManager.GetString("SearchCriteria", resourceCulture);
}
}
For some reason it is always showing up on screen as blank when run. If I replace the textfield with a standard android one and use a standard assignment the text shows up.
android:text="@string/test_string"
So I know that the textfield is there, its on the screen and theres nothing blocking it, its just that textvalue is for some reason not getting set or not rendering (not sure which). Can you advise what the issue might be? If more information is needed please just ask. Thank you.
Update
I added breakpoint to the setter/getter for the binded value:
public string SearchCriteria
{
get => searchCriteria; // Does not get called
set => SetProperty(ref searchCriteria, value); // Is called with an actual value
}
And only the setter fires (with a value) the getter never fires.
Update For further context, we tried setting the text directly on a button in the view using the ViewModel text getter and it works. So there is some sort of issue in the XML binding we don't understand.
Button = view.FindViewById<Button>(Resource.Id.Button);
Button.Text = ViewModel.SearchCriteria
We also made sure explicity bind the viewmodel and view:
ClaimsHistorySearchViewFragment_ : MvxFragment<ClaimsHistorySearchViewModel>
Update We found more issue with the view model. When we assigned a value to the ProptertyChange and explicity changed a value the PropertyChanged did not fire:
public override void OnViewCreated(View view, Bundle savedInstanceState)
{
base.OnViewCreated(view, savedInstanceState);
ViewModel.PropertyChanged += _model_PropertyChanged;
ViewModel.ErrorCode = 0; // _model_PropertyChanged Does NOT fire
}
Note The binding is working when we use fluent mvvm cross binding but not when we use localmvx binding
There was a space in my import
xmlns:local="http://schemas.android.com/apk/res-auto
Once I remove it, it was fixed