Get FontWeight/FontStyle/TextDecorations from WPF RichTextBox

前端 未结 4 451
渐次进展
渐次进展 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:25

    The author of this thread also asked about TextDecorations where you did not provide sample code and its different to use. I post this as a further solution:

    var obj = _myText.GetPropertyValue(Inline.TextDecorationsProperty);
    
                        if (obj == DependencyProperty.UnsetValue)                   
                            IsTextUnderline = false;// mixed formatting 
    
                        if (obj is TextDecorationCollection)
                        {
                            var objProper = obj as TextDecorationCollection;
    
                            if (objProper.Count > 0)                        
                                IsTextUnderline = true; // all underlined                       
                            else                        
                                IsTextUnderline = false; // nothing underlined                   
                        } 
    

提交回复
热议问题