This is a migrated thread and some comments may be shown as answers.

Spellchecking problem

2 Answers 127 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
ASSYST2 - CGI
Top achievements
Rank 1
ASSYST2 - CGI asked on 04 Nov 2013, 08:45 AM
Hello everyone,

We are encountering a little issue with spellchecking function of the richtextbox.

Let me explain the context : we are using Framework 3.5 and the runtime version of the Telerik library is v2.0.50727 for WPF.
Why 3.5? Because we also use Sharepoint 2010 and we have an application working with MVVM design pattern.

So here is our problem : we have a wpf page that creates dynamicly a table (rows and columns are dynamics) with a RichtextBox and each cell. Each cell has the right text and works fine. But whenever we try to use the spellcheck, it doesn't work. We investigated and realised that even if the spellcheck would see the wrong words on the control, you can't change it from the Right click context menu. We then realised that when we open up the context spell checking window, it automatically select the content of the first richtextbox object we have on the page. So even if the text content is the right one, it tries to replace it from the first RichtextBox of the table. Same goes for the Copy and paste functions.

First, we are not using the Telerik rich textbox by itself, we have another control that herits from it :
<UserControl x:Class="Eca.Assyst.Client.Common.RichTextEditor"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
             mc:Ignorable="d" 
             BorderBrush="Transparent" 
             Background="Transparent" 
             x:Name="thisUserControl"
             d:DesignHeight="300" 
             d:DesignWidth="300">
    <Grid>
        <telerik:HtmlDataProvider x:Name="htmlDataProvider"
                                  RichTextBox="{Binding ElementName=richTextBox}" 
                                  Html="{Binding Path=HtmlValue, ElementName=thisUserControl, Mode=TwoWay}">
            <telerik:HtmlDataProvider.FormatProvider>
                <telerik:HtmlFormatProvider>
                    <telerik:HtmlFormatProvider.ExportSettings>
                        <telerik:HtmlExportSettings DocumentExportLevel="Fragment" 
                                                    ExportStyleMetadata="False" 
                                                    StyleRepositoryExportMode="DontExportStyles" 
                                                    StylesExportMode="Inline"
                                                    ExportFontStylesAsTags="True" />
                    </telerik:HtmlFormatProvider.ExportSettings>
                </telerik:HtmlFormatProvider>
            </telerik:HtmlDataProvider.FormatProvider>
        </telerik:HtmlDataProvider>
        <telerik:RadRichTextBox x:Name="richTextBox" 
                                DocumentInheritsDefaultStyleSettings="True" 
                                BorderBrush="Transparent" 
                                Background="Transparent" 
                                AcceptsTab="False" />
    </Grid>
</UserControl>

Here is the control that is used for our table :
<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="DataTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Margin="0,2,0,0"
                d:DataContext="{StaticResource ResourceKey=FindingEntryEditorViewModelMock}">
        <ContentControl x:Name="DropDownContainer"
                        Visibility="{Binding Path=DisplayStatusDropDown, Converter={StaticResource BooleanToVisibilityConverter}}">
            <telerik:RadComboBox x:Name="StatusComboBox"
                                SelectedValuePath="Value"
                                telerik:StyleManager.Theme="Metro"
                                ItemsSource="{Binding StatusItems, Converter={StaticResource EnumToListConverter}}" 
                                SelectedValue="{Binding Path=Entry.Status}">
                <telerik:RadComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label Content="{Binding Path=Text}" Foreground="{Binding Path=Color}"></Label>
                    </DataTemplate>
                </telerik:RadComboBox.ItemTemplate>
            </telerik:RadComboBox>
        </ContentControl>
  
        <Common:RichTextEditor HtmlValue="{Binding Path=Entry.Text, Mode=TwoWay}"
                               GotFocus="richTextBox_GotFocus" 
                               LostFocus="richTextBox_LostFocus"></Common:RichTextEditor>
  
        <my:ReferencesEditor x:Name="referencesEditor" References="{Binding Path=Entry, Converter={StaticResource ResourceKey=ReferenceContainerConverter}}" />
    </StackPanel>

Here is the GridView table we use :
<ScrollViewer HorizontalScrollBarVisibility="Auto"
                                      VerticalScrollBarVisibility="Auto">
                            <StackPanel Orientation="Vertical">
                                <telerik:RadGridView x:Name="gridView"
                                                     RowIndicatorVisibility="Collapsed"
                                                     SelectedItem="{Binding SelectedItem}"
                                                     CanUserReorderColumns="False"
                                                     GridLinesVisibility="Horizontal"
                                                     ShowGroupPanel="False"
                                                     BorderThickness="0"
                                                     AutoGenerateColumns="False"
                                                     CanUserSortColumns="False"
                                                     CanUserFreezeColumns="False"
                                                     ColumnWidth="*"
                                                     BeginningEdit="GridView_OnBeginningEdit"
                                                     ItemsSource="{Binding Path=Finding.Items.List}"
                                                     EnableRowVirtualization="False"
                                                     EnableColumnVirtualization="False"
                                                     telerik:StyleManager.Theme="Windows7">
                                    <telerik:RadGridView.SortDescriptors>
                                        <telerik:SortDescriptor Member="SortOrder" SortDirection="Ascending"/>
                                    </telerik:RadGridView.SortDescriptors>
                                    <telerik:RadGridView.Columns>
                                        <telerik:GridViewDataColumn IsReadOnly="True"
                                                                    DataMemberBinding="{Binding Path=Code}"
                                                                    CellStyle="{StaticResource ResourceKey=CustomCellStyle}"
                                                                    Header="Type"
                                                                    Width="Auto" />
                                        <!-- More columns are added here dynamically by the code behind this file -->
                                    </telerik:RadGridView.Columns>
                                </telerik:RadGridView>
  
                                <AuditProgrammeEditor:FindingErrorSpecificationControl x:Name="ErrorSpecification"
                                                                                       Visibility="{Binding Path=DataContext.ShowAmountsTable, ElementName=MainContainer, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                                                                                       DataContext="{Binding MasterErrorEntry}"
                                                                                       IsEnabled="{Binding Path=DataContext.ReadOnly, ElementName=gridView, Converter={StaticResource ResourceKey=BooleanToInvertedBooleanConverter}}"
                                                                                       Margin="0,0,0,5"/>
                            </StackPanel>
                        </ScrollViewer>

And last but not least, this how we get our DataTemplate for each column :
public DataTemplate GetTemplate(int columnIndex, bool isEnabled)
        {
            var templateXaml = Properties.Resources.FindingTableEntryTemplate;
            templateXaml = templateXaml.Replace("{EntryIndex}", columnIndex.ToString(CultureInfo.InvariantCulture));
            templateXaml = templateXaml.Replace("{IsEnabled}", isEnabled.ToString(CultureInfo.InvariantCulture));
            var stream = new MemoryStream(Encoding.Default.GetBytes(templateXaml));
            return (DataTemplate)XamlReader.Load(stream);
        }

Thanks in advance !

2 Answers, 1 is accepted

Sort by
0
Accepted
Boby
Telerik team
answered on 07 Nov 2013, 09:59 AM
Hello Fabien,
The behavior is known peculiarity related to the fact that by default ContextMenu has one instance shared between all instances of RadRichTextBox. You can work around the issue by creating custom context menu which is non-sharable. It will be downloaded automatically by MEF so you don't need to register it in any way rather that declaring it. The approach is described in this forum answer (the second approach).


Regards,
Boby
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
ASSYST2 - CGI
Top achievements
Rank 1
answered on 07 Nov 2013, 10:01 AM
Thank I'll try to implement that. I'll let you know when I get there!
Tags
RichTextBox
Asked by
ASSYST2 - CGI
Top achievements
Rank 1
Answers by
Boby
Telerik team
ASSYST2 - CGI
Top achievements
Rank 1
Share this question
or