简体   繁体   English

WPF Richtextbox调整大小性能

[英]WPF Richtextbox resizing performance

I have a richtextbox with a flowdocument like this: 我有一个带有这样的flowdocument的richtextbox:

var mcFlowDoc = new FlowDocument();
var para = new Paragraph();
para.Inlines.Add(textBlock1);
para.Inlines.Add(textBlock2);
para.Inlines.Add(textBlock3);
mcFlowDoc.Blocks.Add(para);
richTextBox1.Document = mcFlowDoc;

When I resize the window, there is a small delay in rendering, especially when the number of textblocks is larger (30+) and there is always some flicker. 当我调整窗口大小时,渲染的延迟很小,尤其是当文本块的数量较大(超过30个)并且总是闪烁时。

Is there a way to make resizing faster and smoother? 有没有办法使调整大小更快,更流畅?

In our WPF code, we ran into problems when we started using RichTextBox intensively. 在WPF代码中,当我们开始大量使用RichTextBox时遇到问题。 Not specifically render problems, mostly excessive memory use. 没有专门提出问题,主要是过多的内存使用。

The solution I adopted may also help you: We rendered the document without RichTextBox . 我采用的解决方案也可能对您有所帮助:我们在不使用RichTextBox情况下呈现了文档。 You can convert the context of a RichTextBox to readonly WPF TextBlock . 您可以将RichTextBox的上下文转换为只读WPF TextBlock

When the user selects the control, we replace the TextBlock with a RichTextBox with the same content. 当用户选择控件时,我们用具有相同内容的RichTextBox替换TextBlock

We wrapped the above behavior in a custom control. 我们将上述行为包装在一个自定义控件中。 There is also some tweaking involved to get the TextBlock to render identical to RichTextBox (mostly margin/padding). 还需要进行一些调整才能使TextBlock呈现为与RichTextBox相同(主要是边距/填充)。

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

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