Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Search Bar in Navigation Bar

$
0
0

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)
{}
}


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>