How to Set inline Images Vertically Center in RichTextBox

后端 未结 1 826
青春惊慌失措
青春惊慌失措 2021-01-06 20:38

I am working on WPF, i am display RichText data in RichTextBox for that have taken WindowsFormHost, inside that i am taking WinForm RichTextBox to display RichTextData which

1条回答
  •  时光说笑
    2021-01-06 20:55

    You can use BaselineAlignment on a Run to center align the text. Here is an example:

    
        
            
                
                
                
            
            
            
                
                
                
            
        
    
    

    EDIT:

    To apply the formatting to the entire RichTextBox try calling this method after the RichTextBox is populated:

        public void CenterText()
        {
            var text = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
            text.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Center);
        }
    

    0 讨论(0)
提交回复
热议问题