0

We have a standard SearchView - SearchViewModel binding that works in our Android and Windows Store apps.

There are various places in the app that call ShowViewModel to show the SearchViewModel. In this call we pass the Search Text.

We are now looking to reuse that same ViewModel in Xamarin.iOS.

The UISearchBar examples show the Search Bar filtering data in the current ViewModel.

I want to use it as a way of triggering a ShowViewModel, with the Search text being passed across to the SearchViewModel. That would then take the user from the current View to the Search View.

How do I trap the initiation of the Search so that I can pass the Search Text across to our SearchViewModel using ShowViewModel?

Pat Long - Munkii Yebee
  • 3,592
  • 2
  • 34
  • 68
  • I think there´s a problem with the UISearchBar bindings in MvvmCross. At least I couldn´t make it to work. Is that your issue? I solved that creating a property in the view accesing the searchbar text: ``` public string Query { get { return searchBar.Text; } set { searchBar.Text = value; } } ``` And binding that property to the viewModel: ``` set.Bind(this).For(s => s.Query).To(vm => vm.SearchQuery); ```` – xleon Mar 24 '15 at 03:47
  • Sadly that's not my problem. Your property helps with you with filtering the data in the current ViewModel. I want to take the search text and pass it across to a search View\ViewModel when the user presses enter – Pat Long - Munkii Yebee Mar 24 '15 at 08:58
  • ShowViewModel(new { query = query }); and in your search view model: public void Init(string query) {} – xleon Mar 24 '15 at 17:20
  • @xleon I know how to pass text to the ViewModel :-) What I don't know is where I can make that call. How can I trap the entering of the text and then call ShowViewModel? What event? – Pat Long - Munkii Yebee Mar 25 '15 at 08:20

0 Answers0