I want to have spell checking (the red underlines) enabled for textboxes in my XamDataGrid. I'm building the styles manually in C#, like this:
ret.Setters.Add(new Setter(TextBox.AcceptsReturnProperty, true));
newstyle.Resources.Add(typeof(TextBox), ret);
Then applying that style to the Field.Settings.EditorStyle
But SpellCheck is an attached property, so how can I do it?
Thanks
Ok I can almost get this working using an event handler:
newstyle.Setters.Add(new EventSetter(XamTextEditor.EditModeStartedEvent, new EventHandler<EditModeStartedEventArgs>(SpellCheckEditStart)));
And then..
{
}
This appears to work BUT comes up with erronious spelling mistakes! Almost as if it isn't word-breaking correctly (ie 'work' is a spelling error. Right click and select 'work' as a correction, and it shows 'workk', 2 k's).
Any ideas? Vol 2 hoxfix 1007
Try this:
Create a cutom Field which his editor is XamMasketTexbox.
then assume that f is an object of typeField and configure it:
f.DataType = typeof(string); f.Settings.EditAsType = typeof(string); f.Settings.EditorType = typeof(XamMaskedEditor);
Style s = new Style(typeof(XamMaskedEditor)); //Setter setterMask = new Setter(XamMaskedEditor.MaskProperty, mask); Setter setterMask = new Setter(XamMaskedEditor.MaskProperty, "{char:10:0-9a-zA-Z)"); s.Setters.Add(setterMask); f.Settings.EditorStyle = s;
If you need a list of rules to generarte masks follow this link:
http://help.infragistics.com/Help/NetAdvantage/WPF/2007.2/CLR3.X/HTML/xamEditors_Masks.html
Andrea
A MaskEditor will spell check by default? I don't see any options in your code to turn spell checking on..
I've also tried styling the TextBox (instead of the XamTextEditor) as shown below. But this still word-breaks strangely! Attached in a screenshot, notice that 'wor' of the word 'work' is shown as a spelling error!
Any ideas?
BTW I'm having to construct my styles in code rather than XAML because I'm dynamically building all this from db tables.
textboxstyle.Setters.Add(new EventSetter(TextBox.LoadedEvent, new RoutedEventHandler(SpellCheckLoaded)));
editorstyle.Resources.Add(typeof(TextBox), textboxstyle);
...
private static void SpellCheckLoaded(object sender, RoutedEventArgs e) { ((TextBox)sender).SpellCheck.IsEnabled = true; }
I created a style enabling spell-checking for all TextBoxes within the scope of my grid and got spell checking to work in the text editors.
<Style TargetType="{x:Type TextBox}"> <Setter Property="SpellCheck.IsEnabled" Value="True"/></Style>
Also, John, if you are using XAML anywhere near the scope of your grid, you can define your styles there (perhaps in the container for the grid).
I do need to do this programatically - I'm building by grid fields based on lots of db settings, so the styles have to be dynamicly constructed,
How can I style SpellCheck in C#?? Doing Style st = new Style(typeof(SpellCheck)) throws an exception!
Just an update:
Turns out this is a bug in WPF itself, not the XamDataGrid. It only happens with the UK locale though (am I the only person in the UK using WPF spell checking?!?!).
See this thread:
http://forums.msdn.microsoft.com/en/wpf/thread/ad49ca62-280c-4db4-9780-b277072dccb0/
Ah got it, I was assuming the dependency property had to be on the object I was styling, but I can set it on attached objects too:
textboxstyle.Setters.Add(new Setter(SpellCheck.IsEnabledProperty, true));
So I guess my spell-checking weirdness is something to do with the underlying string, not the xamdatagrid. hmmm.
Update: I've examined the string being shown. No weird characters. Also, cutting the text from the textbox, and pasting it right back in the same box, removes the red-underline! I've tried switching the grid to LazyLoad, but no difference...