We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

sfRichTextBoxAdv how to set selection to all caps etc.

I want to be able to set the selected text to all caps, small caps, and all lowercase, in code-behind. The standard wpf RichTextBox allows this by setting the CharacterCasing dependencyproperty. How to do this in the syncfusion version? (using code-behind).

1 Reply

AP Arumuga Perumal S Syncfusion Team September 11, 2017 05:53 AM UTC

Hi Chris,

Thank you for contacting Syncfusion support.

Currently our WPF SfRichTextBoxAdv does not provide support for character casing property. We have already logged this requirement as feature request. We will implement this feature in any of our upcoming releases. We usually have an interval of at least three months between releases. The feature implementation would also greatly depend on the factors such as product design, code compatibility and complexity. We request you to visit our website periodically for feature related updates.

However, you can replace the selected text to all caps or lower case using Selection.InsertText() API. Using this API will convert the replaced text to single formatting even though the selected text contains different formatting. Also the text will be preserved in converted case on exporting. Kindly refer the sample code below.

C#

 
/// <summary> 
/// Converts the casing of selected text in SfRichTextBoxAdv. 
/// </summary> 
/// <param name="isLower">Specifies whether the text to be converted in lower case.</param> 
public void ConvertCase(bool isLower) 
{ 
    // Gets the selected text. 
    string text = richTextBoxAdv.Selection.Text; 
    // Converts the casing of selected text. 
    string replaceText = isLower ? text.ToLower() : text.ToUpper(); 
    if (!text.Equals(replaceText)) 
    { 
        // Store the current selection positions. 
        string start = richTextBoxAdv.Selection.Start.GetHierarchicalIndex; 
        string end = richTextBoxAdv.Selection.End.GetHierarchicalIndex; 
        // Replace the text to converted casing. 
        richTextBoxAdv.Selection.InsertText(replaceText); 
        // Restore the selection positions. 
        richTextBoxAdv.Selection.Select(richTextBoxAdv.Document.GetTextPosition(start), 
            richTextBoxAdv.Document.GetTextPosition(end)); 
    } 
} 
 


Loader.
Up arrow icon