即使我强制它更新其布局,我似乎也永远无法HasOverflowContent
对 a 开火。RichTextBlock
这是我尝试过的:
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);
}
为什么不HasOverflowContent
表明它确实有溢出内容?
编辑:好的,我能够this.Loaded
在MainPage
构造函数上订阅,并且在这种情况下这个设置确实显示正确,但是,它对我的应用程序来说不够好,所以我如何在加载的事件之外检查这个?