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.

Is it possible to add <SearchBar> control to the <ToolbarItem>?

dellBoydellBoy Member ✭✭

Found a lot of similar Q's on this topic.

But these answers are all 3,4 maybe 5 years old....Is there anything up to date that allows me to add the SearchBar control to the ToolbarItem that doesnt involve writing up a renderer for your Page?? and is also cross platform?

Thanks

Best Answer

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    If you do not want to involve writing up a custom renderer for your page, you can use NavigationPage.TitleView to add SearchBar like following code

     <NavigationPage.TitleView>
            <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
    
                <SearchBar
                    HorizontalOptions="FillAndExpand"
                    Placeholder="Search"
                    PlaceholderColor="Gray"
                    TextColor="White"
                    VerticalOptions="Center" />
            </StackLayout>
        </NavigationPage.TitleView>
    

    Here is running screenshot.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    If you do not want to involve writing up a custom renderer for your page, you can use NavigationPage.TitleView to add SearchBar like following code

     <NavigationPage.TitleView>
            <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
    
                <SearchBar
                    HorizontalOptions="FillAndExpand"
                    Placeholder="Search"
                    PlaceholderColor="Gray"
                    TextColor="White"
                    VerticalOptions="Center" />
            </StackLayout>
        </NavigationPage.TitleView>
    

    Here is running screenshot.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • dellBoydellBoy Member ✭✭

    Ahh excellent, Thanks LeonLu.
    Worked perfectly

Sign In or Register to comment.