Xamarin.forms: SelectedItem for SearchHandler being readonly causing issues with dropdown selection

Created on 29 Jul 2019  ·  4Comments  ·  Source: xamarin/Xamarin.Forms

Description

As this property is readonly it causes some interesting problems. In the Xaminals example your selection opens a new page so everytime you search the SelectedItem property is reset. In my app for example, I have the SearchHandler component as a means to search for an item and add it to an ObservableCollection<> within the same view. The problem that arises is that I cannot add the same item twice consecutively. I must first select another item so ItemSelected is reset before going back to add the item I wanted to add for the second time in a row!
For a bit more detail I have a post on the Xamarin Forums https://forums.xamarin.com/discussion/162196/how-to-set-itemselected-to-null-after-selection-xamarin-shell-search-handler#latest

Steps to Reproduce

  1. Create view with SearchHandler and ListView binded to an ObservableCollection<>
  2. Have the SearchHandler in XAML be binded to a property in your ViewModel (which when set, the value passed is added to the List binded as the ItemsSource to your ListView)
  3. Attempt to select the same item from the dropdown twice. Thats when you will have this issue.

Expected Behavior

e.g. Cheese selected from dropdown twice, two Cheese items added to list

Actual Behavior

Cheese selected twice, first time its added. Second time nothing happens (because SelectedItem is still set to Cheese)

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:

    • iOS:

    • Android:

    • UWP:

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

shell needs-repro ❔ unverified bug

All 4 comments

Hi @iooovolts, thanks for reporting!

Would it be possible to share this with us in a reproduction project? That way we can easier see what you situation is and hopefully get this resolved quickly.

Thanks!

Here you go @jfversluis . This is a basic app which focuses on the bug I described up above. You should not be able to add an ingredient twice consecutively.
https://github.com/iooovolts/SearchHandlerApp

Find an improved copy of your repro project attached. I have added/changed a couple of things. What I basically did is implement a custom search handler that is more suitable for your needs.

You can see all changes by searching for // GV:.

Unless @PureWeen thinks differently I think this works as intended and I will close this for now. I hope this solution will work for you.

SearchHandlerApp-master.zip

I have tested the solution and it works exactly as expected. Thank you for all your help @jfversluis

Was this page helpful?
0 / 5 - 0 ratings