2016-11-15 66 views
0

我給用戶將幾種文本文件格式加載到RichTextBox中的可能性。WPF:修改RTB中Word文檔的行間距

而且我不想行距,所以我加了一個風格融入XAML:

<RichTextBox .....> 
    <RichTextBox.Resources> 
     <Style TargetType="{x:Type Paragraph}"> 
      <Setter Property="Margin" Value="0" /> 
     </Style> 
    </RichTextBox.Resources> 
</RichTextBox> 

這對於除Word文檔的所有文檔工作正常。 Word文檔的行間距保留在我的RichTextBox中。我試過的代碼,我在網上找到了以下幾行,但它使文本消失在RichTextBox的頂部,並融合到下一行:

rtb2Document.SetValue(Paragraph.LineStackingStrategyProperty, LineStackingStrategy.BlockLineHeight); 
rtb2Document.SetValue(Paragraph.LineHeightProperty, 10.0); 

任何想法如何,我可以消除行距對於高行間距的MS Word文檔?

謝謝!

回答

0

我通過修改每個塊來解決它。如果有更好的解決方案,請不要猶豫,讓我知道。這裏是我的:

foreach (Block blCurrentBlock in rtb2Document.Document.Blocks) 
{ 
    Paragraph p = blCurrentBlock as Paragraph; 
    p.Margin = new Thickness(0); 
}