SearchBar control is a View control, which provides a Search Box.
Before reading this article, please go through the article How To Create And Use XAML Content Page In Xamarin.Forms Application For Android And Universal Windows Platform.
After reading this article, you will learn how to add SearchBar control in Xamarin.Forms Application for Android and Universal Windows Platform with XAML and Visual C# in cross platform application development.
The important tools are given below, which are required to developing UWP.
- Windows 10 (Recommended).
- Visual Studio 2015 Community Edition (It is a free software available online).
- Using Visual studio 2015 Installer, enable Xamarin (cross platform mobile development and C#/.NET, while installing/modifying Visual Studio 2015.
Now, we can discuss step by step app development.
Step 1
Open Visual Studio 2015 -> Start -> New Project-> Select Cross-Platform (under Visual C#-> Blank app (Xamarin.Forms Portable)-> Give the suitable name for your app (XamFormSearchBar) ->OK.

Step 2
Now, create project “XamFormSearchBar_Droid”.

Choose the Target and minimum platform version for your Universal Windows Project.

Create project “XamFormSearchBar_UWP”.

Step 3
Afterwards, Visual Studio creates 6 projects and displays Getting Started.XamarinPage. Now, we have to update Xamarin.Forms Reference for Portable Project and XamFormSearchBar_Droid project.
(Please refer How To Create And Use XAML Content Page In Xamarin.Forms Application For Android And Universal Windows Platform)
Step 4
Add a XAML page for SearchBar Control Demo, right click XamFormSearchBar (Portable) project, select ADD-> NewItem.

Select ->CrossPlatform-> FormXamlPage-> Give the relevant name.

Step 5
Add SearchBar Tag, ListView with ItemTemplate and Labels in SearchBarDemo.Xaml are given below.
- <StackLayout Orientation="Vertical">
- <Label/>
- <Label Text=" SearchBar in Xamarin.Forms Application - UWP and Android Demo" FontSize="20" />
- <Label/>
- <Label/>
- <Label/>
- <SearchBar x:Name="searchBar" HorizontalOptions="Center" Placeholder="Search text" TextChanged="OnSearchBarTextChanged" SearchButtonPressed="OnSearchBarButtonPressed" />
- <ListView x:Name="lvSearch" IsPullToRefreshEnabled="true">
- <ListView.ItemTemplate>
- <DataTemplate>
- <TextCell Text="{Binding SName}" /> </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- </StackLayout>









Join the conversation! Your thoughts help the community grow.