在 Xamarin.Forms SearchBar 中禁用 iOS 自动完成

Disable iOS autocomplete in Xamarin.Forms SearchBar

我有一个 Xamarin.Forms SearchBar 可以在远程服务器上搜索信息。此数据显示在搜索栏下方的 ListView 中,如下所示:

伪代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage ... >
    <ContentPage.Content>
        <StackLayout>
            <SearchBar 
                x:Name="SearchBar"
                Placeholder="Search for a business..."
                HorizontalTextAlignment="Start"
                SearchCommand="{Binding PerformSearch}"
                SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
            </SearchBar>
            <ListView 
                x:Name="SearchResults" 
                ItemsSource="{Binding Path=SearchResults}"
                ...
                >
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

是否可以禁用键盘中的 autocomplete/autocorrect?我知道 Text.Entry it is possible to set IsTextPredictionEnabled to false,但我没有看到以类似方式配置 SearchBar 的方法。

是的,根据SearchBar Properties, the Keyboard for the InputView is exposed. Therefore, similar to this answer,可以在XAML中使用x:FactoryMethod属性来实现:

<SearchBar 
    x:Name="SearchBar"
    Placeholder="Search for a business..."
    HorizontalTextAlignment="Start"
    SearchCommand="{Binding PerformSearch}"
    SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
    <SearchBar.Keyboard>
        <Keyboard x:FactoryMethod="Create">
            <x:Arguments>
                <KeyboardFlags>None</KeyboardFlags>
            </x:Arguments>
        </Keyboard>
    </SearchBar.Keyboard>
</SearchBar>