2011-08-05 90 views
6

我正在尝试创建一个滚动文本块。 但它似乎不起作用。 我该如何去做呢? 下面是我的代码: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> 

+1

什么是不工作?这段代码对我来说看起来很好。添加一些文字并尝试滚动。 – keyboardP

+0

它不能被滚动 –

+1

尝试给你的ScrollViewer一个高度值。 – keyboardP

回答

-1

设置scrollviewerHorizo​​ntalBar到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> 
+0

不知道为什么它只是不工作 –

+0

你应该设置ScrollViewer的最大高度。 – Anheledir

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> 
相关问题