Question

I can't seem to ever get HasOverflowContent to fire on a RichTextBlock, even if I force it to update its layout. Here is what I've tried:

public MainPage()
{
    this.InitializeComponent();
    RichTextBlock block = new RichTextBlock();
    RichTextBlockOverflow overflow = new RichTextBlockOverflow();
    block.OverflowContentTarget = overflow;
    block.Width = 100;
    block.Height = 100;
    Paragraph paragraph = new Paragraph();
    for (int i = 0; i < 1000; i++)
    {
        Run run = new Run();
        run.Text = "FILLER";
        paragraph.Inlines.Add(run);
    }
    block.Blocks.Add(paragraph);
    block.UpdateLayout();
    if (block.HasOverflowContent)
    {
        // This line will never be hit.
    }
    MainGrid.Children.Add(block);
}

Why isn't HasOverflowContent signaling it that it does, in fact, have overflow content?

Edit: Okay, I was able to subscribe to this.Loaded on the MainPage constructor and this setting does show up correctly in such a case, however, its not good enough for my application so how can I check this outside of the loaded event?

Was it helpful?

Solution

So, it looks like it has to be added to the Visual Tree. It won't render it otherwise. Once added, I can call RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); and await renderTargetBitmap.RenderAsync(contentToBePrinted); I can make this work for printing from metro apps by adding the RichTextBlock in a Grid with 0 opacity, and all RichTextBlockOverflow's also to that grid on run-time, so that I can get them to render and also check the HasOverflowContent flag. Its the only way I could make it work the way I want it to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top