次の方法で共有


Windows での SearchBar スペル チェック

この .NET マルチプラットフォーム アプリ UI (.NET MAUI) Windows プラットフォーム固有設定では、スペル チェック エンジンと対話できるように SearchBar を有効にします。 これは、boolean添付プロパティをSearchBar.IsSpellCheckEnabled値に設定することにより、XAML で使用されます。

<ContentPage ...
             xmlns:windows="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;assembly=Microsoft.Maui.Controls">
    <StackLayout>
        <SearchBar ... windows:SearchBar.IsSpellCheckEnabled="true" />
        ...
    </StackLayout>
</ContentPage>

また、Fluent API を使用して C# から使用することもできます。

using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
...

searchBar.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().SetIsSpellCheckEnabled(true);

SearchBar.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows> メソッドは、このプラットフォーム固有設定が Windows でのみ実行されるように指定します。 Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecificメソッドは SearchBar.SetIsSpellCheckEnabled 名前空間で、スペル チェック機能のオンとオフを切り替えます。 さらに、SearchBar.SetIsSpellCheckEnabled メソッドを使用すると、SearchBar.GetIsSpellCheckEnabled メソッドを呼び出してスペル チェックを有効にするかどうかを返し、スペルチェック機能を切り替えることもできます。

searchBar.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().SetIsSpellCheckEnabled(!searchBar.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().GetIsSpellCheckEnabled());

その結果、SearchBar に入力されたテキストのスペル チェックが行われ、正しくないスペルがユーザーに示されます。

SearchBar spell check platform-specific.

Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific 名前空間の SearchBar クラスにも、それぞれ SearchBar でスペルチェックを有効または無効にするために使用できる EnableSpellCheck および DisableSpellCheck メソッドがあります。