Partajați prin


SearchBar Spell Check on Windows

This Universal Windows Platform platform-specific enables a SearchBar to interact with the spell check engine. It's consumed in XAML by setting the SearchBar.IsSpellCheckEnabled attached property to a boolean value:

<ContentPage ...
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout>
        <SearchBar ... windows:SearchBar.IsSpellCheckEnabled="true" />
        ...
    </StackLayout>
</ContentPage>

Alternatively, it can be consumed from C# using the fluent API:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
...

searchBar.On<Windows>().SetIsSpellCheckEnabled(true);

The SearchBar.On<Windows> method specifies that this platform-specific will only run on the Universal Windows Platform. The SearchBar.SetIsSpellCheckEnabled method, in the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace, turns the spell checker on and off. In addition, the SearchBar.SetIsSpellCheckEnabled method can be used to toggle the spell checker by calling the SearchBar.GetIsSpellCheckEnabled method to return whether the spell checker is enabled:

searchBar.On<Windows>().SetIsSpellCheckEnabled(!searchBar.On<Windows>().GetIsSpellCheckEnabled());

The result is that text entered into the SearchBar can be spell checked, with incorrect spellings being indicated to the user:

SearchBar spell check platform-specific

Note

The SearchBar class in the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace also has EnableSpellCheck and DisableSpellCheck methods that can be used to enable and disable the spell checker on the SearchBar, respectively.