3

因为您必须在 Windows 8 Metro Apps 中支持多种屏幕分辨率,所以我想拆分我的 RichTextBlock 以显示将在 RichTextBlockOverflow 控件(或多个控件,取决于我必须显示多少文本)中被截断的文本。为了确定我是否必须显示额外的 RichTextBlockOverflow-Control,我检查了我的 RichTextBlocks 的 HasOverflowContent-Property。但它总是返回 false。

它非常容易重现:

  • 创建一个新的“Windows 应用商店 -> 空白应用程序”
  • 将 MainPage.xaml 的 xaml 替换为以下代码:

    <StackPanel Orientation="Horizontal" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <RichTextBlock x:Name="test1" Width="100" Height="300" OverflowContentTarget="{Binding ElementName=test}">
            <Paragraph>
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
                lkj halks dflkjha skld fkla hsdkl hfakl dsflk hasdkl fakl hsdklf halks dflka jhsdhfklaj hsdklf jhakls dflkaj hsdlkfjh alks dflkajh s
            </Paragraph>
        </RichTextBlock>
        <RichTextBlockOverflow x:Name="test" Width="100" Height="300" />
    
    </StackPanel>
    

然后转到文件后面的代码 (MainPage.xaml.cs) 并用该代码替换构造函数:

public MainPage()
{
    this.InitializeComponent();
    if (test.HasOverflowContent)
    {
        // Will never be entered
    }
    if (test1.HasOverflowContent)
    {
        // Will never be entered
    }
}

在 this.InitializeComponent() 中设置断点,看看 HasOverflowContent 永远不会为真。

我究竟做错了什么?或者它是.NET 中的一个错误?

任何帮助将不胜感激;)

和我

4

1 回答 1

2

尝试使用不同的事件,将您的代码放入Page_Loaded我能够开始HasOverflowContent工作的事件中。

于 2012-09-28T15:25:18.833 回答