简体   繁体   English

Mahapps Metro Richtextbox削减了g字母的底部

[英]Mahapps Metro richtextbox cuts bottom of g letter

My problem with the RichTextBox control is that it cuts off the bottom part of 'g', 'q', and 'j' letters of the last Paragraph added to it. 我对RichTextBox控件的问题是,它切断了添加到最后一个段落的“ g”,“ q”和“ j”字母的底部。 My application is a chat, so it adds one paragraph per message to the FlowDocument of this RichTextBox and it scrolls down. 我的应用程序是聊天,因此它将每个消息的一个段落添加到此RichTextBox的FlowDocument中,并向下滚动。

I think this is not the problem of Paragraph because this happens only with the last Paragraph. 我认为这不是段落的问题,因为这仅在最后一段出现。 When a new one is added and the old is scrolled upper then it doesn't have this problem. 当添加一个新的并且旧的向上滚动时,就没有这个问题。

The XAML code looks like this: XAML代码如下所示:

<Border Grid.Row="0" BorderThickness="0,1" BorderBrush="Gray">
    <ScrollViewer Margin="0,5">
        <RichTextBox IsUndoEnabled="False" IsReadOnly="True" BorderThickness="0" IsDocumentEnabled="True" Background="Transparent">
            <FlowDocument />
        </RichTextBox>
    </ScrollViewer>
</Border>

And I add a new Paragraph with this C# code: 然后用此C#代码添加一个新的段落:

Paragraph p = new Paragraph();
p.Margin = new Thickness(0, 2, 0, 2);
p.Inlines.Add(new Run(msg.Text));
rtbDocument.Blocks.Add(p);

I hope that somebody knows a clever solution for this problem, thanks in advance! 我希望有人知道这个问题的聪明解决方案,在此先感谢您!

Ps.: I don't know the exact name of this problem, so I would be happy if somebody would modify the title of this question to a proper one :) 附注:我不知道这个问题的确切名称,所以如果有人将这个问题的标题修改为一个合适的问题,我会很高兴的:)

I think it is related to line stacking. 我认为这与线堆叠有关。 Line stacking strategy on MSDN . MSDN上的线堆叠策略

I used following approach without problems : 我使用以下方法没有问题:

    <Border Grid.Row="1" BorderThickness="0,1" BorderBrush="Gray" Grid.RowSpan="2">                
          <RichTextBox x:Name="rtbDocument" ScrollViewer.VerticalScrollBarVisibility="Auto" IsUndoEnabled="False" IsReadOnly="True" BorderThickness="5" IsDocumentEnabled="True" Background="Transparent" Margin="0,34,0,69">
             <FlowDocument/>
          </RichTextBox>                
     </Border>

Paragraph p = new Paragraph();            
p.FontSize = 20;
p.Margin = new Thickness(0, 5, 0, 5);
p.Inlines.Add(new Run("some gqgb qqj"));
rtbDocument.Document.Blocks.Add(p);

// //

Your problem is reproduced if I do following changes to FlowDocument in your RichTextBox : 如果我对RichTextBox中的FlowDocument进行以下更改,则会重现您的问题:

<FlowDocument LineHeight="20" LineStackingStrategy="BlockLineHeight" />

or, to your code like : 或者,对于您的代码,例如:

Paragraph p = new Paragraph();
p.LineHeight = 20;
p.LineStackingStrategy = LineStackingStrategy.BlockLineHeight;

or, 要么,

<FlowDocument LineStackingStrategy="BlockLineHeight" />

p.LineHeight = 20;

See figure below : 参见下图:

RichTextBox文本损坏

Removing LineStackingStrategy altogether will work as it will use default value of MaxHeight. 完全删除LineStackingStrategy将起作用,因为它将使用MaxHeight的默认值。 Or, you can set it explicitly : 或者,您可以显式设置它:

<FlowDocument LineStackingStrategy="MaxHeight" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM