Scrollbar and Scrollviewer with Windows Phone

I just figured out a nice one concerning the interesting topic of the scrollbars with Windows Phone.

I had a hard time getting a scrollbar appear around my canvas. I then decided to change my code to replace the canvas with a grid, by replacing the SetValue (Canvas.TopProperty, y) and SetValue (Canvas.LeftProperty, x) with .Margin = new Thickness(x, y, 0, 0);

Still no result… In the end, after many tests,  I understood that somehow, the ScrollViewer computes the difference wetween its own height and its content height. And by setting its height to a smaller value than its content’s, it worked!

Like this:

<ScrollViewer Height=”800″ VerticalScrollBarVisibility=”Auto”>
<Grid x:Name=”MyGrid” Height=”1600″ />

And it worked!