Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Search Bar in Navigation Bar

Hello every one,

I am trying to add search bar in the navigation bar in forms. i know that its not possible directly, but can be achieved using renderer.

So i tried to implement one and add search bar, but i am not sure if i am doing it right.

in IOS

using System;
using Xamarin.Forms.Platform.iOS;
using UIKit;
using Xamarin.Forms;
using test.iOS;
using test;

[assembly: ExportRenderer(typeof(XNP), typeof(SBNavigationRenderer))]
namespace test.iOS
{
public class SBNavigationRenderer : NavigationRenderer
{
UISearchBar searchBar;
UISearchDisplayController searchController;
public SBNavigationRenderer ()
{
searchBar = new UISearchBar{
BarTintColor = UIColor.Blue,

        };

        searchController = new UISearchDisplayController (searchBar, this){
            DisplaysSearchBarInNavigationBar = true,

        };

        searchController.SearchBar.TextChanged += (object sender, UISearchBarTextChangedEventArgs e) => 
        {
            Console.Write("XXXX");
        };

    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        this.NavigationBar.Add (searchBar);




    }
}

}

in common project

public class XNP : NavigationPage
{
public XNP(Page root):base(root)
{}
}

Posts

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited October 2015

    Go through this sample

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited October 2015

    I think this SO Post will be helpful to you :smile:

  • AtulHirveAtulHirve USMember

    Thanks Vaikesh, But the sample is using xib files and i have xamarin forms application. about the SO Post, i have done that for the Search bar already. but haven't got anything for the navigation page. thanks for replying.

Sign In or Register to comment.