0
votes

I have a datagrid with spell checking enabled on one of the columns. The spell checker uses the default dictionary, however I would like to add a custom dictionary so that the spell checker has access to the domain specific terms added by the user.

The column is defined as follows:

<DataGrid.Columns>
    <DataGridTextColumn x:Name="dgcComments" Header="Comment" Width="*" Binding="{Binding Path=Comment, Mode=TwoWay, UpdateSourceTrigger=PropertyChange}">
        <DataGridColumn.ElementStyle>
            <Style TargetType="TextBlock">
                <Setter Property="TextWrapping" Value="Wrap" />
                <Setter Property="Padding" Value="2,0,2,2" />
                <Setter Property="TextAlignment" Value="Left" />
            </Style>
        </DataGridColumn.ElementStyle>
        <DataGridColumn.EditingElementStyle>
            <Style TargetType="TextBox">
                <Setter Property="TextWrapping" Value="Wrap" />
                <Setter Property="AcceptsReturn" Value="True" />
                <Setter Property="Padding" Value="2,0,2,2" />
                <Setter Property="TextAlignment" Value="Left" />
                <Setter Property="MaxLength" Value="4000" />
                <Setter Property="SpellCheck.IsEnabled" Value="True" />
            </Style>
        </DataGridColumn.EditingElementStyle>
    </DataGridTextColumn>
    ...
</DataGrid.Columns>

I know I can't add the dictionary in the xaml - SpellCheck.CustomDictionaries doesn't have a setter, only add and remove methods. Is there a way to add the dictionary in the code behind? I'm stumped; I can't work out how to get access to the TextBox editing element in order to call TextBox.SpellCheck.CustomDictionary.Add().

1

1 Answers

0
votes

This should solve your problem as stated in question above. https://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck.customdictionaries(v=vs.110).aspx

uri description - https://msdn.microsoft.com/en-us/library/aa970069(v=vs.100).aspx

xmlns:sys="clr-namespace:System;assembly=System" 
<DataGrid.Columns>
        <DataGridTextColumn x:Name="dgcComments" Header="Comment" Width="*" Binding="{Binding Path=Comment, Mode=TwoWay, UpdateSourceTrigger=PropertyChange}">
            <DataGridColumn.ElementStyle>
                <Style TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="Wrap" />
                    <Setter Property="Padding" Value="2,0,2,2" />
                    <Setter Property="TextAlignment" Value="Left" />
                </Style>
            </DataGridColumn.ElementStyle>
            <DataGridColumn.EditingElementStyle>
                <Style TargetType="TextBox">
                    <Setter Property="TextWrapping" Value="Wrap" />
                    <Setter Property="AcceptsReturn" Value="True" />
                    <Setter Property="Padding" Value="2,0,2,2" />
                    <Setter Property="TextAlignment" Value="Left" />
                    <Setter Property="MaxLength" Value="4000" />
                    <Setter Property="SpellCheck.IsEnabled" Value="True" />
                   <Setter Property="SpellCheck.CustomDictionaries">
                        <Setter.Value>
                            <sys:Uri>pack://application:,,,/customwords.lex</sys:Uri>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGridColumn.EditingElementStyle>
        </DataGridTextColumn>
        ...
    </DataGrid.Columns>