Hi,
I am trying to use XamSpellChecker in a popup with a textbox as its spell check target as shown below:
<ig:XamSpellChecker x:Name="igSpellChecker" MaxHeight="20"> <ig:XamSpellChecker.SpellCheckTargets> <Binding ElementName="NarrativeTextBox" Path="Text" Mode="TwoWay"/> </ig:XamSpellChecker.SpellCheckTargets> </ig:XamSpellChecker> <TextBox x:Name="NarrativeTextBox" Grid.Row="0" Grid.Column="1" Text="{Binding displayValue,Mode=TwoWay}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Width="300" AcceptsReturn="True" FontFamily="{StaticResource BaseFont_Family}" FontSize="{StaticResource BaseFont_Size}" > <TextBox.Foreground> <SolidColorBrush Color="{StaticResource Black}"/> </TextBox.Foreground> </TextBox>
And when the SpellCheck method is called, a null-reference exception is thrown by the method. When I wrote a test application with just a popup with a text box and the spell checker, it worked fine. But as a part of a bigger application, a null reference exception is thrown. Any idea what might have made it throw that exception?
I tried to reproduce your issue, but without avail. I don't see any problems in the code you provided. Could you provide some more details - exception stack trace, etc ?
Regards,
Hi Georgi,
As I mentioned, the code worked fine in a separate application with just the popup. But when it is made a part of a bigger application, I had this problem :(
Here are the exception details:
Message: "Object reference not set to an instance of an object."
StackTrace: at Infragistics.Controls.Interactions.XamSpellChecker.SpellCheck() at LimitEnquiry.Modules.NarrativePopupViewModel.OnSpellCheck(Object o) at Microsoft.Practices.Prism.Commands.DelegateCommand`1.<>c__DisplayClass6.<.ctor>b__2(Object o) at Microsoft.Practices.Prism.Commands.DelegateCommandBase.Execute(Object parameter) at Microsoft.Practices.Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute(Object parameter) at Microsoft.Practices.Prism.Commands.CommandBehaviorBase`1.ExecuteCommand() at Microsoft.Practices.Prism.Commands.ButtonBaseClickCommandBehavior.OnClick(Object sender, RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
It's hard to tell what's the cause of this, without the ability to debug it more deeply.
My guess is that there's something wrong with your SpellCheckTarget bindings.
Is the text element you're trying to SpellCheck in the same visual tree as the SpellChecker? The Popup breaks the Visual Tree, so if your textbox is outside the popup, and the SpellChecker is inside it (or vice-versa), your SpellCheckTarget binding won't work, and you'll get this exception.
So, my suggestion is to verify the binding you specified as a SpellCheck target is valid.
Hope this helps,
I do not have idea if they are in the same visual tree, but did figure out that in the above code, if I change the SpellCheckTarget from "NarrativeTextBox" to "displayValue" (to which text box is bound), then everything works fine :)
Many thanks for the help :)
Sujeevan.