Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable ScrollViewer VerticalScrollBarVisible if content fits

I am currently writing my very first Windows Phone (8) App which also is my very first Xaml Application. So it is likely I just did not find the solution for my problem on my own, because I don't know which words to feed google. I tried, but found nothing useful. I found that one, but it does not help:

How to disable "scroll compression" in ScrollViewer

Here is the important part of my XAML:

<ScrollViewer VerticalScrollBarVisibility="Auto">
    <StackPanel VerticalAlignment="Top">
         <TextBlock x:Name="InfoText" TextWrapping="Wrap" VerticalAlignment="Top" Text="VersionInfoText"/>
    </StackPanel>
</ScrollViewer>

I will programmatically change the content of my TextBlock InfoText. The text might be short enough to fit in completely, or it might be rather long. That is why I embedded it into a ScrollViewer. (By the way, there will be further Controls added to the StackPanel later.)

The ScrollViewer produces these "overbounce" effects if it cannot scroll any further. That is nice if the text is large, but when there is nothing to scroll I don't want this effect to be visilbe.

I tried VerticelScrollBarVisibility="Disable", which successfully disables the effect. Now my question:

Can I automatically (by XAML-Magic) switch between Auto and Disable depending on the Height of my StackPanel and the Hight of my ScrollViewer?

I was hoping Auto would do the trick, but it does not (tested in the VS2013 Emulator WVGA).

like image 277
Knowleech Avatar asked Apr 13 '14 14:04

Knowleech


2 Answers

In VS2013 setting VerticalScrollBarVisibility="Auto" worked for me.

like image 118
Brett Avatar answered Sep 28 '22 20:09

Brett


Try adding this attribute to your ScrollViewer

VerticalScrollMode="Auto"

Also try disabling the HorizontalScrollMode and HorizontalScrollBarVisiblity attributes.

Let me know if this doesn't work. I will then have to make a sample app to see if I can make that work for you. Right now I am just guessing. Try it.

like image 20
Preetesh Avatar answered Sep 28 '22 18:09

Preetesh