Change style of selected Text in RichTextBox

后端 未结 2 776
挽巷
挽巷 2020-12-18 13:28

How can I change styles (such as Font, FontSize, Brush) of selected Text in RichTextBox ?

Update : Let\'s say I\'ve a RichTextBox

2条回答
  •  难免孤独
    2020-12-18 14:29

    For a WPF RichTextBox, you have to use the ApplyPropertyValue method to a TextRange. You can get the selected TextRange using the Selected property of the RichTextBox instance.

    var selection = myRichTextBox.Selection;
    if (!selection.IsEmpty)
        selection.ApplyPropertyValue(TextElement.FontSizeProperty, 10.0);
    

提交回复
热议问题