MAUI页面SearchBar在Windows正常显示,iOS移动端不显示问题
MAUI SearchBar在iOS端不显示问题
开发的MAUI页面中,SearchBar在Windows设备上显示正常,但在iOS移动端测试时完全无法显示。尝试设置SearchBar的背景色和文本色后仍无效果,目前发现两种可临时让SearchBar显示的方法:
- 将SearchBar放在布局代码的最顶部
- 移除
LocationSuggestionsListView代码块
原始XAML代码
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:root="clr-namespace:Orbis.Mobile" x:Class="Orbis.Mobile.ActivitiePage" xmlns:viewmodel="clr-namespace:Orbis.Mobile.ViewModels" Title=""> <ContentPage.Resources> <root:BytesToImageConverter x:Key="ToImage" /> </ContentPage.Resources> <ContentPage.Content> <ScrollView> <StackLayout Orientation="Vertical"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <BoxView x:Name="Box" BackgroundColor="White" /> <!--<SearchBar HorizontalOptions="Center" WidthRequest="300"/>--> <SearchBar x:Name="SearchBar" Placeholder="Search activities by Location" TextChanged="OnSearchBarTextChanged" WidthRequest="300" /> <ListView x:Name="LocationSuggestionsListView" ItemsSource="{Binding Suggestions}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Label Text="{Binding .}" /> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <ImageButton Grid.Row="0" Source="ic_add.png" x:Name="Plus" Clicked="Plus_Clicked" VerticalOptions="Center" HorizontalOptions="End" HeightRequest="35" Aspect="AspectFit" /> <!--<Picker x:Name="Location" HorizontalOptions="Center" Title="Location" ItemsSource="{Binding ItemsWithLocation}" ItemDisplayBinding="{Binding Location}" />--> <StackLayout Grid.Row="4" HeightRequest="600" HorizontalOptions="FillAndExpand" Margin="0"> <RefreshView Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}"> <CollectionView x:Name="ItemsListView" ItemsSource="{Binding FilteredItems}" SelectionMode="None"> <CollectionView.ItemTemplate> <DataTemplate> <StackLayout Padding="10" > <StackLayout.GestureRecognizers> <TapGestureRecognizer Tapped="OnItemTapped" /> </StackLayout.GestureRecognizers> <StackLayout Orientation="Horizontal"> <Image Source="{Binding Image, Converter={StaticResource ToImage}}" HeightRequest="50" WidthRequest="70"/> <Label Text="{Binding Text}" LineBreakMode="WordWrap" Style="{DynamicResource ListItetextStyle}" FontSize="16" TextColor="Black"/> </StackLayout> </StackLayout> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </RefreshView> </StackLayout> </Grid> </StackLayout> </ScrollView> </ContentPage.Content> </ContentPage>
修改后的测试代码
<StackLayout Orientation="Vertical"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <BoxView Grid.Row="0" x:Name="Box" BackgroundColor="White" /> <!--<SearchBar HorizontalOptions="Center" WidthRequest="300"/>--> <SearchBar Grid.Row="1" x:Name="SearchBar" Placeholder="Search activities by Location" TextChanged="OnSearchBarTextChanged" WidthRequest="300" /> <ListView Grid.Row="2" x:Name="LocationSuggestionsListView" ItemsSource="{Binding Suggestions}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Label Text="{Binding .}" /> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
显示效果截图
Windows正常显示:

iOS异常显示:

内容的提问来源于stack exchange,提问作者Chris Curt
相关产品推荐
相关产品推荐

