2

I am trying to add a SearchBar to the TitleView so that the SearchBar takes the full width of the TitleBar without hardcoding the width property (WidthRequest). But the SearchBar is displayed with the minimum required width and does not take the full width. Does anyone know how it can be achieved?

The code I am using:

var searchBar = new SearchBar
{
    Placeholder = "Search",
    HorizontalOptions = LayoutOptions.FillAndExpand
};
NavigationPage.SetTitleView(this, searchBar);
Kamir
  • 21
  • 5

1 Answers1

0

Try to wrap the SearchBar within a StackLayout, just like this

 <NavigationPage.TitleView>
            <StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
                  <SearchBar HorizontalOptions="FillAndExpand"/>
            </StackLayout>
        </NavigationPage.TitleView>
Bruno Caceiro
  • 7,035
  • 1
  • 26
  • 45
  • Hi Bruno, thanks for the advice, but it did not work. Width of the SearchBar is still limited to the width of its Placeholder, so it's not the full width of the screen – Kamir Sep 29 '18 at 12:26