Mvvmcross: android.support.v7.widget.SearchView Query binding not working

Created on 29 May 2017  路  4Comments  路  Source: MvvmCross/MvvmCross

Steps to reproduce

View:

<android.support.v7.widget.SearchView
    android:id="@+id/searchView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    local:MvxBind="Query SearchString" />

ViewModel:

 private string _searchString;
 public string SearchString
 {
     get { return _searchString; }
     set
     {
         _searchString = value;
         RaisePropertyChanged(() => SearchString);
     }
 }

Expected behavior

Query should bind correctly.

Actual behavior

Only the getter is working when the viewmodel loads. The setter doesn't.

I/MvxBind(7360):  15,87 Failed to create target binding for binding Query for SearchString

Configuration

Version: 5.0.1

Platform:

  • [ ] iOS
  • [x] Android
  • [ ] WPF
  • [ ] UWP
android bug

All 4 comments

Query property does not have a Setter. The target binding needs SetImplementation, to invoke SetQuery().

Just played with the Target Binding a bit. It should work From the View -> ViewModel. So if you edit the text inside of the SearchView, your ViewModel should be updated. However, as is now, if you edit the SearchString in the ViewModel, it won't be reflected in the SearchView. Will prepare a fix for that now.

As for AppCompat SearchView, we have TargetBindings for that too. They are in MvvmCross.Droid.Support.V7.AppCompat. Make sure you replace MvxAndroidSetup with MvxAppCompatSetup instead.

Confirmed, it is now working after replacing MvxAndroidSetup with MvxAppCompatSetup. Thanks a lot! :)

Was this page helpful?
0 / 5 - 0 ratings