wpf icon indicating copy to clipboard operation
wpf copied to clipboard

WPF on .NET 8.0 > TextBox.SpellCheck custom dictionary has no effect

Open vsfeedback opened this issue 1 year ago • 12 comments

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version] Hello,

I am currently facing the problem that the SpellCheck of the TextBox WPF-Control does not seem to load my lexicon file correctly.

Per documentation I am using the following code to load the dictionary:

txtContent.Language = System.Windows.Markup.XmlLanguage.GetLanguage("de-DE");
txtContent.SpellCheck.CustomDictionaries.Clear();
txtContent.SpellCheck.CustomDictionaries.Add(new Uri(@"C:\temp\test.lex", UriKind.Absolute));
txtContent.SpellCheck.IsEnabled = true;

The TextBox is defined in XAML as follows:

<TextBox x:Name="txtContent" DockPanel.Dock="Top"
         BorderThickness="0"
         Margin="0,0,0,0" Width="Auto" Height="Auto"
         SpellCheck.IsEnabled="false"
         IsInactiveSelectionHighlightEnabled="true"
         AcceptsReturn="True" AcceptsTab="True"
         Visibility="Visible"
         VerticalScrollBarVisibility="Auto" TextChanged="txtContent_TextChanged"
         SelectionChanged="TextBox_SelectionChanged" IsReadOnlyCaretVisible="True"
         ScrollViewer.ScrollChanged="txtContent_ScrollViewer_ScrollChanged"
         PreviewMouseWheel="txtContent_PreviewMouseWheel">
</TextBox>

The file "test.lex" contains the following lines:

#LID 1031
Datenbox
Dokumentenboard
Infoboard

Still, when I type the word "Datenbox" in the TextBox control, it underlines the word and tries to correct it.

When I retrieve the custom dictionaries using "SpellCheck.GetCustomDictionaries", I can see that the dictionary was in fact loaded. It just isn't applied for some reason.

Project Information:

<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<PlatformTarget>x64</PlatformTarget>

Any help or hints would be greatly appreciated!

Kind regards, Lukas


Original Comments

Feedback Bot on 9/11/2024, 07:10 AM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Sep 11 '24 05:09 vsfeedback

Do you have a repro project?

miloush avatar Sep 11 '24 09:09 miloush

@miloush I created a public repo with a minmal reproducible sample, you can find it here: https://github.com/LukinTV/WPF-SpellCheck-CustomDictionary.

Just be sure to change the absolute path to the .lex-file to wherever you cloned to project: txtSpellCheck.SpellCheck.CustomDictionaries.Add(new Uri(@"C:\temp\Repro\WPF-SpellCheck-CustomDictionary\custom.lex", UriKind.Absolute));

LukinTV avatar Sep 11 '24 13:09 LukinTV

Reference https://github.com/dotnet/wpf/issues/9701

lindexi avatar Sep 12 '24 06:09 lindexi

Reference #9701

Also, https://stackoverflow.com/questions/77258504/wpf-spellcheck-on-windows-11-systems/. This seems to be a common problem.

LukinTV avatar Sep 12 '24 07:09 LukinTV

I've tried to investigate the problem, but I've had no luck

lindexi avatar Sep 12 '24 08:09 lindexi

Even with default spell check it sometimes works and sometimes not

alraseensaad avatar Sep 17 '24 23:09 alraseensaad

We have exact the same issue! Custom dictionaries are ignored in Windows 11, in Windows 10 all works fine. Any solutions for that issue?

tualatin avatar Jan 21 '25 12:01 tualatin

@tualatin Sorry, I can not find any solution.

lindexi avatar Jan 22 '25 01:01 lindexi

I duplicated this issue using the WPF-Samples code in[https://github.com/microsoft/WPF-Samples/archive/refs/heads/main.zip], with the project in Documents/Spell Checking/CustomDictionaries. The textbox spellchecking pays no attention to the sample CustomDictionary.lex file.

garzooma avatar Mar 06 '25 19:03 garzooma

@garzooma Can you share the OS version you've replicated it on?

h3xds1nz avatar Mar 06 '25 20:03 h3xds1nz

@garzooma Can you share the OS version you've replicated it on?

Edition Windows 11 Pro Version 24H2 Installed on ‎2/‎6/‎2025 OS build 26100.3194 Experience Windows Feature Experience Pack 1000.26100.48.0

garzooma avatar Mar 06 '25 20:03 garzooma

We are seeing this issue too in a net 8 app on current windows 11 builds. The issue being that we do enable spell checking in WPF controls, we have persistent custom dictionaries, and these custom dictionaries are ignored.

dev-3mensio avatar Apr 14 '25 11:04 dev-3mensio