문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top