xamarin.form(可移植的xaml.form跨平台)-on android,SearchBar和StackLayout无效

时间:2016-11-12 14:12:18

标签: c# android xamarin.forms

我根本不知道为什么SearchBar不会在StackLayout上显示 我写了以下xaml标签:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:App3"
         x:Class="App3.MainPage">

  <StackLayout>
    <SearchBar IsVisible="True" IsEnabled="True" Placeholder="Search" 
     BackgroundColor="Red" TextColor="White"/>
    <Label Text="asdasd "/>

  </StackLayout>
</ContentPage>

但我唯一看到的是标签,而不是搜索栏,因为你看到我添加了IsVisible和IsEnabled属性,即使它是多余的只是为了确保问题, 请注意,如果我单独放置搜索栏,它可以正常工作:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:App3"
         x:Class="App3.MainPage">

    <SearchBar  Placeholder="shsdfdsf"/>

</ContentPage>

它在absolutelayout上工作正常,感谢所有助手!

1 个答案:

答案 0 :(得分:0)

好吧我已经弄清楚了,显然不像标签/按钮和许多其他它不适合&#34;搜索栏的requestHeight和requestwidth属性(或者至少在这里 - 尽管它很奇怪,因为它应该在任何地方都行为相同) 但写作:

    <SearchBar Placeholder="asdasdasf23" HorizontalOptions="Fill" HeightRequest="50" />
确定了它,但如果有其他人知道为什么它没有工作,那么如果我能听到如何修复它会很棒。