Bug 44454 - SearchBar fails to trigger SearchButtonPressed event
Summary: SearchBar fails to trigger SearchButtonPressed event
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
Depends on:
Reported: 2016-09-17 01:56 UTC by Scott Weaver
Modified: 2017-06-19 18:56 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Scott Weaver 2016-09-17 01:56:15 UTC
I have been trying to use a SearchBar in a Xamarin.Forms app - targeted for Android right now.
The SearchButtonPressed event will not trigger.
The TextChanged event works fine but SearchButtonPressed does not trigger.
I have tried using the SearchCommand option as well and it also does not get triggered.

I have tested this on a Galaxy S6 & S7 (Android 6.0.1) and Galaxy Tab S 10.5 (Android 5.0.2) with the same results on all devices.

This is a very stripped down version of the SearchBarDemo from the "Creating Mobile Apps with Xamarin.Forms" book by Charles Petzold (https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/)

I have not been able to find any other reports of this not working so please let me know if you can get this to work - is there something wrong with my implementation? - or confirm that it fails in which case I assume this is a Xamarin bug and will submit it.

Xamarin Sudio: 6.1 (build 5441)
Target Android version: Automatic - use target framework version (API 23)

Created a new Solution: Multiplatform, Xamarin.Forms - Forms App - C#
Project Name: SearchBarDemo
Took all default settings.

Replaced the files with the contents below.


    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
            <SearchBar x:Name="searchBar" 
                       Placeholder="Search text" 
                       SearchButtonPressed="OnSearchBarButtonPressed" />
            <Label x:Name="searchText" BackgroundColor="Yellow" HorizontalOptions="Center" /> 
            <Label x:Name="searchResults" BackgroundColor="Silver" HorizontalOptions="Center" /> 


using System;
using Xamarin.Forms;
namespace SearchBarDemo
    public partial class SearchBarDemoPage : ContentPage
        public SearchBarDemoPage()

        void OnSearchBarTextChanged(object sender, TextChangedEventArgs args)
            searchText.Text = searchBar.Text;
            searchResults.Text = string.Empty;

        void OnSearchBarButtonPressed(object sender, EventArgs args)
            searchResults.Text = searchBar.Text;
Comment 1 Paul DiPietro [MSFT] 2016-10-03 23:57:08 UTC
I'm currently unable to reproduce this on an emulator, as the event fires. Please let me know if you experience this in an emulator opposed to an actual device. If it does, uploading the actual reproduction from your machine might be of help to see if there are any discrepancies anywhere.
Comment 2 Scott Weaver 2016-10-08 17:31:37 UTC
This appears to be a combination of my lack of understanding of the user interface and what I consider poor user interface design.

I followed your suggestion to test this with an emulator rather than a physical device. During testing I noticed that the key on the virtual keyboard changed to a search (magnifying glass) icon and tapping that key triggered the SearchButtonPressed event. 

I had previously focused on the search (magnifying glass) icon next to the text field where the search text was entered. My report was based on the fact that tapping the search icon next to the text field did not trigger the event. I had missed the search icon on the virtual keyboard when working with my device.

The Xamarin API documentation provides no explanation of what triggers the event but Charles Petzold's book says of the SearchButtonPressed event: "It is triggered by a particular button on the keyboard in the same location as the completed button for Entry but possibly labeled differently."

Re-reading this passage made me realize that the event was tied to the (virtual) keyboard button not the search icon next to the text entry field.

This seems to me to be a very poor user interface implementation to have two identical icons that do not provide the same behavior.

Is there anything that can be done to improve this by making the search icon next to the search text entry field respond to a tap and trigger the SearchButtonPressed event?

I could not find any way to address this icon directly to cause this to happen.

Sorry for the misunderstanding of how the user interface is intended to function but as I said this seems to me as poor UI design.
Comment 3 Paul DiPietro [MSFT] 2017-06-19 18:56:31 UTC
For upkeep, setting to resolved as it appears to have been self-answered.