How to add SearchBar and NavigationPage.PrefersLargeTitles IOS using xaml?

timarshatimarsha Member ✭✭

Hello! How to add SearchBar and NavigationPage.PrefersLargeTitles IOS using xaml?

Best Answer


  • NMackayNMackay GBInsider, University mod

    @timarsha said:
    Hello! How to add SearchBar and NavigationPage.PrefersLargeTitles IOS using xaml?

    You can add you can add your own searchbar to the Title using the TitleView feature (Forms 3.2 upwards...recommend 3.4 SR1)

  • timarshatimarsha Member ✭✭

    I added SearchBar, but it is located above leargeTitle



  • timarshatimarsha Member ✭✭


  • BrandonMinnickBrandonMinnick USXamarin Team Xamurai
    edited August 10

    There's currently no way to do it in XAML.

    Here’s a blog post I did that shows how to do it for Xamarin.Forms and it covers both iOS and Android:

    And here’s a sample app showing the completed code:

    To answer your question, here’s how to do it for Xamarin.iOS.


    Use a Xamarin.Forms Platform-Specific to use LargeTitles

    using Xamarin.Forms.PlatformConfiguration;
    using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
    public class App : Xamarin.Forms.Application
        public App()
            var navigationPage = new Xamarin.Forms.NavigationPage(new MyContentPage());
            MainPage = navigationPage;

    Xamarin.Forms Page

    public class MyContentPage : ContentPage, ISearchPage,
        public MyContentPage()
            SearchBarTextChanged += HandleSearchBarTextChanged
        public event EventHandler<string> SearchBarTextChanged;
        public void OnSearchBarTextChanged(in string text) => SearchBarTextChanged?.Invoke(this, text);
        void HandleSearchBarTextChanged(object sender, string searchBarText)
            //Logic to handle updated search bar text

    ISearchPage Interface

    public interface ISearchPage
        void OnSearchBarTextChanged(in string text);
        event EventHandler<string> SearchBarTextChanged;

    iOS Custom Renderer

    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using MyNamespace;
    using MyNamespace.iOS;
    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    [assembly: ExportRenderer(typeof(MyContentPage), typeof(SearchPageRenderer))]
    namespace MyNamespace.iOS
        public class SearchPageRenderer : PageRenderer, IUISearchResultsUpdating
            bool _isFirstAppearing = true;
            public override void WillMoveToParentViewController(UIViewController parent)
                var searchController = new UISearchController(searchResultsController: null)
                    SearchResultsUpdater = this,
                    DimsBackgroundDuringPresentation = false,
                    HidesNavigationBarDuringPresentation = false,
                    HidesBottomBarWhenPushed = true
                searchController.SearchBar.Placeholder = string.Empty;
                parent.NavigationItem.SearchController = searchController;
                DefinesPresentationContext = true;
            public override void ViewDidAppear(bool animated)
                //Work-around to ensure the SearchController appears when the page first appears
                if (_isFirstAppearing)
                    ParentViewController.NavigationItem.SearchController.Active = true;
                    ParentViewController.NavigationItem.SearchController.Active = false;
                    _isFirstAppearing = false;
            public void UpdateSearchResultsForSearchController(UISearchController searchController)
                if (Element is ISearchPage searchPage)
Sign In or Register to comment.