Highlight selected text and insert inline ui object

2 posts, 0 answers
  1. Chris
    Chris avatar
    12 posts
    Member since:
    Sep 2012

    Posted 05 Jan 2011 Link to this post

    I am trying to highlight selected text in the radrichtextbox. I was looking at an example from back in June and it appears that it is not working for me. Now I understand the method ChangeTextColor has been changed to ChangeTextHighlightColor. While the forums post says this code highlights the selected text.This code selects the current line and highlights the whole thing not the selected text. Let me know if I am doing something wrong but this code does not work for me. In addition to this requirement. I also have a requirement to insert an inline ui object. Now I can get this inserted at the end of the selection or where the caret is currently but I cannot get this inline object inserted at the beginning of the selection.  

    private void HighLight_Click(object sender, RoutedEventArgs e)
        DocumentPosition position = new DocumentPosition(this.richTextBox.Document.CaretPosition);
  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 07 Jan 2011 Link to this post

    Hello Chris,

     The code block you have pasted actually clears the selection and highlights the line that the caret is currently positioned in.
    (I assume that by 

    you mean 
    as there is no ChangeTextBackColor(Color color) method in RadRichTextBox's API.)
    If you want to change the highlight color of the selected text, the following line is sufficient, as this method operates on the selected text:

    You can also use the command that RadRichTextBoxRibbonUI exposes and bind the command as shown in our demo:

    <telerik:HighlightColorPicker AutomaticColor="Transparent" Height="22" NoColorText="No color" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeFontHighlightColorCommand}" SelectedColor="Yellow" Width="36" />
    (Note that the whole RichTextBoxRibbonUI's DataContext is bound to the Commands property of RadRichTextBox.)

    The InsertInline(Inline inline) method of RadRichTextBox inserts the inline at the current CaretPosition. If there is selected text, it is replaced. You can, however, manipulate the CaretPosition and the selection in code-behind to adapt this behavior to match your needs.
    if (!this.radRichTextBox.Document.Selection.IsEmpty)
    InlineUIContainer containter = new InlineUIContainer(new Button(), new Size(75, 23));

    If you have any other questions, do not hesitate to contact us again.

    Kind regards,
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top