Search code examples
c#windows-runtimericheditbox

How do you underline selected text in a WinRT RichEditBox?


I'm currently making an application which includes a rich text editor, however I'm having some issues with applying formatting to the text. Specifically, I'm having an issue with underlining the selected text. Here is my current code.

    private void UnderlineButton_Click(object sender, RoutedEventArgs e)
    {
        ITextSelection selectedText = rtfEditor.Document.Selection;
        if (selectedText != null)
        {
            ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
            charFormatting.Underline = UnderlineType.Single;
            //charFormatting.Underline = FormatEffect.;
            selectedText.CharacterFormat = charFormatting;
        }
    }

Help would be appreciated!


Solution

  • You can do it like that:

    rtfEditor.Document.Selection.CharacterFormat.Underline = UnderlineType.Thin;
    

    or

    ITextSelection selectedText = rtfEditor.Document.Selection;
    selectedText.CharacterFormat.Underline = UnderlineType.Double;