Windows Phone 7中的可滚动文本块

时间:2011-08-05 03:36:31

标签: c# windows-phone-7

我正在尝试创建一个可滚动的文本块。 但它似乎没有用。 我应该怎么做呢? 以下是我的代码:

    <Grid x:Name="ContentGrid" Grid.Row="1">
        <ScrollViewer>
        <TextBlock Height="517" HorizontalAlignment="Left" Margin="33,16,0,0" Name="textBlockRules" Text="" VerticalAlignment="Top" Width="414" FontSize="25" TextWrapping="Wrap" /></ScrollViewer>   

             

3 个答案:

答案 0 :(得分:2)

即使你没有明确提到,我猜你的目的是展示一些大文字而不会被砍掉。

对于这样的要求,stackoverflow上有一些有用的线程: 1. Need to show large amount of text on windows phone 7 screen 2. Programmatically determining max fit in textbox (WP7)

另一方面,如果你想要的只是序列中的文本块,你可以使用数据绑定到列表的ListBox。

答案 1 :(得分:1)

您必须设置ScrollViewer的最大高度,并可以将滚动条的可见性设置为自动。

以下是msdn

中的示例
<ScrollViewer Height="200" Width="200" HorizontalScrollBarVisibility="Auto" Canvas.Top="60" Canvas.Left="340">
<TextBlock Width="300" TextWrapping="Wrap" 
    Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." />
</ScrollViewer>

答案 2 :(得分:-1)

将scrollviewer Horizo​​ntal Bar设置为visibal,使文本框伸展并确保文本足够长,如下所示:

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Name="Scroller">
        <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="100" Width="{Binding ElementName=Scroller, Path=ViewportWidth}"
        TextWrapping="Wrap" Text="Some really long text that should probably wordwrap when you resize the window." />
</ScrollViewer>