Scrolling a TextBlock
Asked Answered
G

4

9

I have a TextBlock and a Textbox in the same location. Depending on what mode the user is in, I make one visible and the other collapsed. This is working fine, but how can I make the Textblock scrollable? I figured I should use a ScrollViewer, but I don't know why it's not working. I've tried messing around with the height (auto and fixed), but it won't scroll. My xaml is this:

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Width="478"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Width="462" Height="197"  Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>

Thanks!

Grevera answered 30/6, 2010 at 23:14 Comment(0)
A
2

You might like to refer to the discussion and MSFT confirmation that text control scrolling is still a work in progress as at the current CTP. Beta shouldnt be too far away, hopefully more on this then.

Alkyne answered 1/7, 2010 at 6:14 Comment(1)
Thanks, I hope they release a refresh soon because I keep having to put off aspects of my application.Grevera
E
23

Don't put a height in the textbox. This worked perfectly for me:

    <ScrollViewer Height="192" HorizontalAlignment="Left" Margin="12,34,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="404">
        <TextBlock VerticalAlignment="Top"  Name="textBlock1" Text="TextBlock" Width="378" TextWrapping="Wrap" />
    </ScrollViewer> 
Ely answered 18/6, 2011 at 17:56 Comment(0)
A
2

You might like to refer to the discussion and MSFT confirmation that text control scrolling is still a work in progress as at the current CTP. Beta shouldnt be too far away, hopefully more on this then.

Alkyne answered 1/7, 2010 at 6:14 Comment(1)
Thanks, I hope they release a refresh soon because I keep having to put off aspects of my application.Grevera
P
1

The below code works : As your child control(ie., textblock) has a height and width that is not equal to the width and height of your scroll viewer and hence the scroll bars don't display. I have just given same height and width as the scroll viewer for the controls defined inside it it works.

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Height="285" Width="480"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Height="285" Width="480" Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>
Poor answered 1/7, 2010 at 7:30 Comment(1)
Thanks I tried the code, but it only moved slightly. I couldn't scroll smoothly all the way to the end. I guess it's a current limitation.Grevera
S
0

If you want the contents to scroll, make sure a scrollbar is visible.

<TextBox Text="{Binding SomethingReallyLong}" 
 TextWrapping="Wrap" 
 VerticalScrollBarVisibility="Visible"/>        
Silverweed answered 30/6, 2010 at 23:19 Comment(1)
Sorry, forgot to mention, this is for Windows Phone 7. I've edited my original tags. Displaying the scrollbar doesn't work as it simply makes the textbox editable and the textblock doesn't scroll either.Grevera

© 2022 - 2024 — McMap. All rights reserved.