可滚动文本块在windows phone 7

本文关键字:windows phone 滚动 文本 | 更新日期: 2023-09-27 18:04:29

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

    <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>   

可滚动文本块在windows phone 7

即使您没有明确提到,我猜您的目的是显示一些大文本而不被剪切。

对于这样的要求,stackoverflow上有一些有用的线程:1. 需要在windows phone 7屏幕上显示大量文本2. 以编程方式确定文本框的最大拟合度(WP7)

另一方面,如果你想要的只是按顺序排列文本块,你可以使用绑定到列表的ListBox

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

下面是来自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>

设置scrollviewerHorizontalBar为visibal,设置textbok拉伸并确保文本足够长,就像这样:

    <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>