TitleView中的Xamarin.Forms SearchBar需要全宽

时间:2018-09-27 18:06:04

标签: c# xamarin.forms width searchbar titleview

我试图将SearchBar添加到TitleView,以便SearchBar占用TitleBar的整个宽度,而不用硬编码width属性(WidthRequest)。但是SearchBar会以最小的所需宽度显示,并且不会占据整个宽度。有谁知道如何实现?

我正在使用的代码:

val firstName: String = "".empty()
val firstName: String = "".EMPTY

1 个答案:

答案 0 :(得分:0)

尝试将SearchBar包裹在StackLayout中,就像这样

 <NavigationPage.TitleView>
            <StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
                  <SearchBar HorizontalOptions="FillAndExpand"/>
            </StackLayout>
        </NavigationPage.TitleView>