6

I am trying to create a scrollable text block. But it dont seem to works. How should i go about doing it? Below is my code:

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

beny lim
  • 1,312
  • 3
  • 28
  • 57

3 Answers3

2

Even though you didn't mention explicitly, I'm guessing that your aim is to show some large text without getting chopped.

For such a requirement there are helpful threads on stackoverflow: 1. Need to show large amount of text on windows phone 7 screen 2. Programmatically determining max fit in textbox (WP7)

On the other hand, if all you want is have text blocks in a sequence, you can use a ListBox that is databound to a list.

Community
  • 1
  • 1
moonlightdock
  • 1,358
  • 13
  • 14
1

You have to set the maximum height of the ScrollViewer and could set the Visibility for the Scrollbars to Auto.

Here is the example from the 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>
Anheledir
  • 4,337
  • 7
  • 32
  • 34
-1

Set scrollviewerHorizontalBar to visibal, make textbok stretch and make sure your text is long enough, something like this:

    <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>
Nghia Nguyen
  • 2,585
  • 4
  • 25
  • 38