0
votes

I have a RichEditBox and a ToggleButton, which toggles the spell checking of the RichEditBox. By default, the spell checking is disabled. Therefore, when I type some nonsense in the editor, of course, it isn't underlined red. When I toggle the button after that, and insert some more rubbish characters, only the newly inserted stuff is marked as wrong, but not the characters inserted before enabling the spell checking.

Hence I'm looking for a possibility to "reload" the spell checking, so that the complete content of the RichEditBox is checked.


My issue in pictures:

Step 1: Inserting some random rubbish with disabled spellchecking

[enter image description here]

Step 2: Enabling spellchecking and typing the same characters again:

[enter image description here]


<Page
    x:Class="FontSizeTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FontSizeTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ToggleButton x:Name="SpellCheckingButton" Grid.Row="0" Checked="HandleSpellCheckingButton_Checked">Spell Checking</ToggleButton>
        <RichEditBox x:Name="Editor" IsSpellCheckEnabled="False" Grid.Row="1"></RichEditBox>
    </Grid>
</Page>



public sealed partial class MainPage : Page {
    public MainPage() {
        this.InitializeComponent();
    }

    private void HandleSpellCheckingButton_Checked(object sender, RoutedEventArgs e) {
        bool isChecked = ((ToggleButton) sender).IsChecked.GetValueOrDefault();
        Editor.IsSpellCheckEnabled = isChecked;
    }
}
1

1 Answers

1
votes

Reload spell checking of UWP RichEditBox

The problem is Checked event only occurs in ToggleButton checked state, you just set Editor.IsSpellCheckEnabled as true but have not edit it back to false when ToggleButton uncheck state. We suggest you modify IsSpellCheckEnabled property in ToggleButton click event like the following.

private void SpellCheckingButton_Click(object sender, RoutedEventArgs e)
{
    bool isChecked = ((ToggleButton)sender).IsChecked.GetValueOrDefault();
    Editor.IsSpellCheckEnabled = isChecked;
}

xaml

<ToggleButton
    x:Name="SpellCheckingButton"
    Grid.Row="0"
    Click="SpellCheckingButton_Click"  
    >
    Spell Checking
</ToggleButton>

Update

When I toggle the button after that, and insert some more rubbish characters, only the newly inserted stuff is marked as wrong, but not the characters inserted before enabling the spell checking.

I misunderstand your question, it's by default. If you want to re-check all the content, we need re-set the content like the following.

private void SpellCheckingButton_Click(object sender, RoutedEventArgs e)
{
    bool isChecked = ((ToggleButton)sender).IsChecked.GetValueOrDefault();
    Editor.IsSpellCheckEnabled = isChecked;
    var temp = string.Empty;
    Editor.Document.GetText(TextGetOptions.FormatRtf, out temp);
    Editor.Document.SetText(TextSetOptions.FormatRtf, string.Empty);
    Editor.Document.SetText(TextSetOptions.FormatRtf, temp);
}