1
votes

I have a Xamarin.Forms SearchBar to search for information on a remote server. This data is displayed in a ListView below the searchbar like the following:

iOS Xamarin.Forms SearchBar with autocomplete/autocorrect

Pseudocode:

<?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>

Is it possible to disable the autocomplete/autocorrect in the keyboard? I know for a Text.Entry it is possible to set IsTextPredictionEnabled to false but I don't see a way to configure a SearchBar in a similar way.

1

1 Answers

4
votes

Yes, according to the SearchBar Properties, the Keyboard for the InputView is exposed. Therefore, similar to this answer, it can be achieved in the XAML by using the x:FactoryMethod attribute:

<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>