WPF on .NET 8.0 > TextBox.SpellCheck custom dictionary has no effect
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)
Do you have a repro project?
@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));
Reference https://github.com/dotnet/wpf/issues/9701
Reference #9701
Also, https://stackoverflow.com/questions/77258504/wpf-spellcheck-on-windows-11-systems/. This seems to be a common problem.
I've tried to investigate the problem, but I've had no luck
Even with default spell check it sometimes works and sometimes not
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 Sorry, I can not find any solution.
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 Can you share the OS version you've replicated it on?
@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
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.