Getting Started with UWP Spell Checker
18 Nov 20183 minutes to read
Spell checking operation can be done on Text editor controls through UWP Spell Checker in UWP application by implementing IEditorProperties interface.
The following steps helps to add UWP Spell Checker.
-
Create a UWP project in Visual Studio and include
Syncfusion.SfSpellChecker.UWPassembly. -
Create an instance of
UWP Spell Checkerusing “Syncfusion.UI.Xaml.Controls” namespace.
Syncfusion.UI.Xaml.Controls.SfSpellChecker spellChecker = new Syncfusion.UI.Xaml.Controls.SfSpellChecker();- Create instance of Button and TextBox to input control for SpellCheck.
<Page
x:Class="SpellCheckerSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SpellCheckerSample">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBox x:Name="Textbox" TextWrapping="Wrap" VerticalContentAlignment="Top"
Text="Ribbn illustrats the Microsoft illustrats Offce 2007 UI.
Our prduct exposes most of the featres of the new UI and eeps intact
winhth the Slverlight architecture. Configuring and designing
the layout is very easy through XAML code.
Ribbon tabs and Ribbon bars are the main client area in Ribbon.
Ribbon tabs will allow your end users to navigate and find the
appropriate tools for the task at hand. The Ribbon bars will
contain the Ribbon tools." VerticalAlignment="Stretch" />
<Button HorizontalAlignment="Left" Content="Spell Check" Click="Button_Click" />
</Grid>
</Page>- Inherit
IEditorPropertiesinterface ofUWP Spell Checkerand Initialize all the methods and properties in interface.
public class TextSpellEditor:IEditorProperties
{
TextBox textbox;
public TextSpellEditor(Control control)
{
ControlToSpellCheck = control;
}
public Control ControlToSpellCheck
{
get
{
return textbox;
}
set
{
textbox = value as TextBox;
}
}
public string SelectedText
{
get
{
return textbox.SelectedText;
}
set
{
textbox.SelectedText = value;
}
}
public string Text
{
get
{
return textbox.Text;
}
set
{
textbox.Text = value;
}
}
public void Select(int selectionStart, int selectionLength)
{
textbox.Select(selectionStart, selectionLength);
}
public bool HasMoreTextToCheck()
{
return !string.IsNullOrEmpty(textbox.SelectedText) || textbox.Text.Length > 0;
}
public void Focus()
{
textbox.Focus();
}
public void UpdateTextField()
{
}
}- In Click event of button call SpellCheck method to TextBox.
private void Button_Click(object sender, RoutedEventArgs e)
{
TextSpellEditor Editor = new TextSpellEditor(Textbox);
spellChecker.PerformSpellCheckUsingDialog(Editor);
}
- Selected word in suggestion list can be replaced by clicking the Replace button in the spell check dialog.