Wednesday, 11 September 2013

TextBlock with vertical scrollbar only

TextBlock with vertical scrollbar only

I have a TextBlock which may contain a long text so I want to add a
vertical scroll bar to it. My initial attempt was to wrap a ScrollViewer
around it. That works but the problem is that when I zoom in, the width is
zoomed also. I tried disabling the horizontal scroll bar like this:
<ScrollViewer IsTabStop="True" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
But it didn't solve the problem. I also tried binding the width:
Width="{Binding ElementName=Scroller, Path=ViewportWidth}"
It didn't help either.
So, my question is, how can I add vertical scrollbar to it but have a
fixed width and wrapped text for the TextBlock inside? Here's my full
code:
<ScrollViewer Grid.Row="1" IsTabStop="True"
VerticalScrollBarVisibility="Auto">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Top" TextWrapping="Wrap"
TextAlignment="Center"/>
</ScrollViewer>

No comments:

Post a Comment