2011-08-05 23 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> 
相關問題