Get FontWeight/FontStyle/TextDecorations from WPF RichTextBox

前端 未结 4 420
渐次进展
渐次进展 2021-01-14 13:02

How can I detect the current text formatting at the cursor position in a WPF RichTextBox?

4条回答
  •  遥遥无期
    2021-01-14 13:30

    Try the code below where rtb is the RichTextBox:

    TextRange tr = new TextRange(rtb.Selection.Start, rtb.Selection.End);
    object oFont = tr.GetPropertyValue(Run.FontFamilyProperty);
    

提交回复
热议问题