private static void OnFind(object sender, ExecutedRoutedEventArgs e)
        {
            RichEditorControl control  = (RichEditorControl)sender;
            string            findText = (string)control.FindComboBox.Text;

            TextPointer navigator = control.RichTextBox.Selection.IsEmpty ?
                                    control.RichTextBox.Document.ContentStart :
                                    control.RichTextBox.Selection.End.GetNextInsertionPosition(LogicalDirection.Forward);

            while (navigator != null && navigator.CompareTo(control.RichTextBox.Document.ContentEnd) < 0)
            {
                TextRange wordRange = WordBreaker.GetWordRange(navigator);

                if (wordRange == null)
                {
                    break;
                }

                string wordText = wordRange.Text;
                if (wordText == findText)
                {
                    control.RichTextBox.Selection.Select(wordRange.Start, wordRange.End);
                    return;
                }

                navigator = wordRange.End.GetNextInsertionPosition(LogicalDirection.Forward);
            }
        }
        private static void OnApplyNormalStyle(object sender, ExecutedRoutedEventArgs e)
        {
            RichEditorControl control   = (RichEditorControl)sender;
            Paragraph         paragraph = control.RichTextBox.Selection.Start.Paragraph;

            paragraph.FontFamily = new FontFamily("Verdana");
            paragraph.FontSize   = 11;
        }
        private static void OnApplyHeading3Style(object sender, ExecutedRoutedEventArgs e)
        {
            RichEditorControl control   = (RichEditorControl)sender;
            Paragraph         paragraph = control.RichTextBox.Selection.Start.Paragraph;

            paragraph.FontFamily = new FontFamily("Arial");
            paragraph.FontSize   = 13;
            paragraph.FontWeight = FontWeights.Bold;
        }
        private static void OnSelectionParagraphIsRightToLeftPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            richEditorControl.RichTextBox.Selection.ApplyPropertyValue(Paragraph.FlowDirectionProperty, (value == true) ? FlowDirection.RightToLeft : FlowDirection.LeftToRight);
            richEditorControl.OnSelectionChanged(null, null);
        }
        private static void OnSelectionIsNumberingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            EditingCommands.ToggleNumbering.Execute(null, richEditorControl.RichTextBox);
            richEditorControl.OnSelectionChanged(null, null);
        }
        private static void OnSelectionIsAlignJustifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            richEditorControl.RichTextBox.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, (value == true) ? TextAlignment.Justify : TextAlignment.Left);
            richEditorControl.OnSelectionChanged(null, null);
        }
        private static void OnSelectionIsUnderlinePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            richEditorControl.RichTextBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, (value == true) ? System.Windows.TextDecorations.Underline : null);
            richEditorControl.OnSelectionChanged(null, null);
        }
        private static void OnSelectionIsItalicPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            richEditorControl.RichTextBox.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, (value == true) ? FontStyles.Italic : FontStyles.Normal);
            richEditorControl.OnSelectionChanged(null, null);
        }
        private static void OnIsSpellCheckEnabledPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)o;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            bool value = (bool)e.NewValue;

            if (value != null)
            {
                richEditorControl.RichTextBox.SpellCheck.IsEnabled = value;
            }
        }
        private static void OnSelectionFontSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichEditorControl richEditorControl = (RichEditorControl)d;

            if (richEditorControl._updateSelectionPropertiesPending)
            {
                return;
            }
            string value = (string)e.NewValue;

            if (value != null)
            {
                richEditorControl.RichTextBox.Selection.ApplyPropertyValue(TextElement.FontSizeProperty, value);
                richEditorControl.OnSelectionChanged(null, null);
            }
        }