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

Spell Checker in RichtTextBox

1 Answer 139 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
hari
Top achievements
Rank 1
hari asked on 14 Sep 2011, 09:16 PM
Hello There,
I am facing some difficulty in the simple radrichtexteditor.  

my question's are -
1. How can get spell check enabled in my rich text box with context menu ?? ( I mean Once I right click on the wrong word, it should showup all the suggested words like MSWord)
2. On the context menu of radrichtextbox, how can I get the images for cut, copy and paste.
3. Even though  I set the font family: Verdana and font Size:10, still its showing me different.  How can override the default font??

Here is the code:
NonModelPopUp.xaml
<telerik:RadWindow x:Class="COC.eFiling.Common.Presentation.Views.NonModelPopUp"
        xmlns:telerikribbontab="clr-namespace:Telerik.Windows.Controls.RibbonBar;assembly=Telerik.Windows.Controls.RibbonBar"
        xmlns:dictionary="clr-namespace:Telerik.Windows.Documents.Proofing;assembly=Telerik.Windows.Documents.Proofing.Dictionaries.En-US"
        xmlns:contextmenu="clr-namespace:Telerik.Windows.Controls.RichTextBoxUI;assembly=Telerik.Windows.Controls.RichTextBoxUI"
                   Header="NonModelPopUp" Height="300" Width="500"
                  >
 
     
    <Grid>
         
        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="35" />
        </Grid.RowDefinitions>
        
            <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Height="25" DataContext="{Binding Path=Commands, ElementName=editor}" >
                <telerik:RadRibbonButton CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand ="{Binding Path=CutCommand}" Size="Small"  SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/cut.png" Text="Cut" />
                <telerik:RadRibbonButton CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=CopyCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/copy.png" Text="Copy" />
                <telerik:RadRibbonButton CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=PasteCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/paste.png" Text="Paste" />
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=UndoCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/undo.png" Text="Undo" />
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=RedoCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/redo.png" Text="Redo" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleBoldCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/bold.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleItalicCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/italic.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleUnderlineCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/underline.png"/>
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=IncrementFontSizeCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/font-increasesize.png" />
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=DecrementFontSizeCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/font-decreasesize.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleBulletsCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/list-bullets.png" />
                <telerik:RadRibbonToggleButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleNumberedCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/list-numbered.png" />
                <telerik:RadRibbonToggleButton CommandParameter="Left" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeTextAlignmentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/alignleft.png" Text="Align Left" />
                <telerik:RadRibbonToggleButton CommandParameter="Center" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeTextAlignmentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/aligncenter.png" Text="Center" />
                <telerik:RadRibbonToggleButton CommandParameter="Right" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeTextAlignmentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/alignright.png" Text="Align Right" />
                <telerik:RadRibbonToggleButton CommandParameter="Justify" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeTextAlignmentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/alignjustify.png" Text="Justify" />
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=DecrementParagraphLeftIndentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/outdent.png" />
                <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=IncrementParagraphLeftIndentCommand}" Size="Small" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/indent.png" />
            </StackPanel>
 
        <StackPanel Orientation="Horizontal" Grid.Row="1" Name="NoteType_ddl" Height="25" >
            <TextBlock Text="NoteType" Width="60" Margin="15,0,5,0" VerticalAlignment="Center" />
            <ComboBox Width="150" Height="20" Margin="5,0,5,0"
                               ItemsSource="{Binding NoteTypes}"
                               DisplayMemberPath="Description"
                               SelectedValuePath="Id"
                                SelectedItem="{Binding Path=SelectedNoteType, Mode=TwoWay}"
                              />
        </StackPanel>
 
        <telerik:RadRichTextBox  x:Name="editor"  Grid.Row="2" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
                                  IsSelectionMiniToolBarEnabled="False" IsImageMiniToolBarEnabled="False" FontFamily="Verdana" FontSize="5"
                                  LayoutMode="Flow" VerticalContentAlignment="Top" IsSpellCheckingEnabled="False"
                                  DataContext="{Binding ElementName=editor, Path=Commands}" HyperlinkNavigationMode="Click"
                                  >
            <telerik:RadDocument LineSpacing="1" />
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="_menuRtbFormat" FontFamily="Verdana" FontSize="10" HorizontalContentAlignment="Left">
                    <telerik:RadMenuItem x:Name="_cutContextMenu" Command="{Binding CutCommand}" Header="Cut" FontFamily="Verdana" FontSize="10" />
                    <telerik:RadMenuItem x:Name="_copyContextMenu" Command="{Binding CopyCommand}" Header="Copy" FontFamily="Verdana" FontSize="10" />
                    <telerik:RadMenuItem x:Name="_pasteContextMenu" Command="{Binding PasteCommand}" Header="Paste" FontFamily="Verdana" FontSize="10" />
                    <!--<telerik:RadMenuItem IsSeparator="True" />-->
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </telerik:RadRichTextBox>
         
        <StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center" >
            <Button Content="Save" Height="25" Width="100" Margin="5,5,5,0" Click="Button_Click" />
            <Button Content="Cancel" Height="25" Width="100" Margin="5,5,5,0" Click="Button_Click_1" />
        </StackPanel>
      
    </Grid>
 
 
</telerik:RadWindow>

NonModelPouUp.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
 
using Telerik.Windows.Controls;
using System.IO;
using Telerik.Windows.Documents.Proofing;
using System.Globalization;
 
using Telerik.Windows.Controls.RichTextBoxUI.Dialogs;
using Telerik.Windows.Controls.RichTextBoxUI;
 
namespace COC.eFiling.Common.Presentation.Views
{
    /// <summary>
    /// Interaction logic for NonModelPopUp.xaml
    /// </summary>
    public partial class NonModelPopUp : RadWindow
    {
        public NonModelPopUp()
        {
            
             
            InitializeComponent();
           
            
        }
 
        //private void LoadDictionary(Stream tdfFileStream)
        //{
        //    RadDictionary dictionary = new RadDictionary();
        //    dictionary.Load(tdfFileStream);
        //    ((DocumentSpellChecker)this.editor.SpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture);
        //}
 
       private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
 
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
 
 
    }
}

Please advise me.

Thanks
krish

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 19 Sep 2011, 05:42 PM
Hi Krish,

In order to get spell checking working in RadRichTextBox you must set its property IsSpellCheckingEnabled property to true. True is the default value of this property, but in your snippet you have set it to false.
RadRichTextBox comes with a predefined ContextMenu, which shows spell checking suggestions for misspelled words out of the box. You don't need to add any code for it, just add a reference to the required assemblies listed here. More information on the default context menu and possible approaches for customization can also be found in our online documentation.
As for your last question, in order to set default font properties on the rich text box, you also have to set the DocumentInheritsDefaultStyleSettings to True. You can refer to this article on more details regarding this matter.

Best wishes,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
hari
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or