I want to build a book app, a RichTextblock with many RichTextblockOverflows, I create the overflows in code-behind, and add them to the stackpanel in a scrollviewer. I tested my app and found that it finished creating the overflows quickly, but after that it will block for a while(which is unbearable) to show the overflows in UI. I registered the LayoutUpdated event of the stackpanel and found that it would be triggered a long time after overflows were created.
How can I improve the performance? Thanks
while (true)
{
// for existing columns just set their width
var overflow = CreateOverflow(columnWidth, margin, lastOverflow);
lastOverflow = overflow;
overflow.Measure(availableSize);
_layoutPanel.Children.Add(overflow);
if (!overflow.HasOverflowContent)
{
overflow.UpdateLayout();
}
if (!overflow.HasOverflowContent)
{
_layoutPanel.LayoutUpdated += _layoutPanel_LayoutUpdated;
break;
}
}