因爲您必須在Windows 8 Metro應用程序中支持多種屏幕分辨率我想分割我的RichTextBlock以顯示將在RichTextBlockOverflow控件(或多個控件,取決於我必須展示多少文本)。 爲了確定是否需要顯示額外的RichTextBlockOverflow-Control,我檢查了我的RichTextBlocks的HasOverflowContent-Property的 。但它總是返回false。RichTextBlockOverflow.HasOverflowContent在Windows 8 Metro應用程序中始終爲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中的錯誤?
任何幫助將是非常讚賞;)
安迪
您應該使用不透明度爲0的畫布,如Microsoft提供的示例。 – Borzh