Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling a TextBlock

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!

like image 312
Skoder Avatar asked Jun 30 '10 23:06

Skoder


People also ask

How do I make text scroll?

To make your text scroll right (i.e. from left to right), use behavior="scroll" and direction="right". Like this: Here is some scrolling text... left to right! To make your text scroll up (i.e. from bottom to top), use behavior="scroll" and direction="up".

How to show automatic vertical scroll bar in WPF textbox?

How to Show Automatic Vertical Scroll bar in WPF TextBox? If you have a TextBox and wish to scroll bars in a TextBox , then you can use the ScrollViewer attached properties as shown below. Video Player is loading.

How do I display scrollable text in XAML?

Create one or more buttons to activate display of your scrollable text within the Xaml for the page on which it will be displayed. For example an About button and a Privacy Policy button (I placed these buttons within a Grid in Grid.Row=”0”):

How do I select text in a textblock?

This example demonstrates a TextBlock with text selection enabled and text wrapping enabled. If using a keyboard for text selection within a TextBlock, the user must first activate Caret Browsing (with the app in the foreground, press F7).


3 Answers

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> 
like image 158
xarzu Avatar answered Sep 20 '22 18:09

xarzu


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.

like image 25
Mick N Avatar answered Sep 23 '22 18:09

Mick N


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>
like image 24
Malcolm Avatar answered Sep 23 '22 18:09

Malcolm