For those of you not familiar with Silverlight or the ScrollViewer control, we have just the thing for you. The ScrollViewer control for the Windows Phone 7 platform is a content control. What this means is that it is used to manage and organize other controls within it.

The only downfall to the ScrollViewer control is that it can only have one child control. This may seem like a hindrance, but there is a way to work around this. We can add a child control to our ScrollViewer that is also a content control, such as a StackPanel or Grid, which can contain multiple controls within them.

Let’s begin with today’s example by creating a new project. Now in our XAML file, let’s add a ScrollViewer control. We can also go ahead and set the HorizontalScrollBar and VerticalScrollBar to Auto. What this does is that lets say we enter a control within our ScrollViewer that we know we will need to scroll; the ScrollViewer will automatically determine the dimensions of the child control and set the scroll equal to it.

We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.

Code Block
MainPage.xaml
ScroolViewer set to Auto
<ScrollViewer Height="218" HorizontalAlignment="Left" Margin="18,0,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="450" HorizontalScrollBarVisibility="Auto" Grid.Row="1">
</ScrollViewer>
Now let’s add a StackPanel control to demonstrate this. Let’s also set the height and width of the StackPanel control as well to Auto. We now need something to put within our StackPanel control, I will be using TextBlock controls. Just add about 11 TextBlocks with a height of 50.

We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Code Block
MainPage.xaml
StackPanel within ScrollViewer
<ScrollViewer Height="218" HorizontalAlignment="Left" Margin="18,0,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="450" HorizontalScrollBarVisibility="Auto" Grid.Row="1">
    <StackPanel Height="Auto" Name="stackPanel1" Width="Auto">
        <TextBlock Height="50" Name="textBlock1" Text="TextBlock 1" Width="Auto" />
        <TextBlock Height="50" Name="textBlock2" Text="TextBlock 2" Width="Auto" />
        <TextBlock Height="50" Name="textBlock3" Text="TextBlock 3" Width="Auto" />
        <TextBlock Height="50" Name="textBlock4" Text="TextBlock 4" Width="Auto" />
        <TextBlock Height="50" Name="textBlock5" Text="TextBlock 5" Width="Auto" />
        <TextBlock Height="50" Name="textBlock6" Text="TextBlock 6" Width="Auto" />
        <TextBlock Height="50" Name="textBlock7" Text="TextBlock 7" Width="Auto" />
        <TextBlock Height="50" Name="textBlock8" Text="TextBlock 8" Width="Auto" />
        <TextBlock Height="50" Name="textBlock9" Text="TextBlock 9" Width="Auto" />
        <TextBlock Height="50" Name="textBlock10" Text="TextBlock 10" Width="Auto" />
        <TextBlock Height="50" Name="textBlock11" Text="TextBlock 11" Width="Auto" />
    </StackPanel>
</ScrollViewer>
You can run the application now to see what the functionality is of the ScrollViewer control.

We can also do this with an Image control within the ScrollViewer. Create a second ScrollViewer control with an Image control as its child. We can then set the source to an image we add to our project, and then be sure to set the size of the Image control larger than that of the ScrollViewer to see how they work together.
Code Block
MainPage.xaml
Image within ScrollViewer
<ScrollViewer Height="347" HorizontalAlignment="Left" Margin="0,248,0,0" Name="scrollViewer2" VerticalAlignment="Top" Width="468" Grid.Row="1" HorizontalScrollBarVisibility="Auto">
    <Image Height="600" Name="image1" Stretch="Fill" Width="800" Source="/WP7ScrollViewerTut;component/sunset.jpg" />
</ScrollViewer>
And there you have it; this is the basic functionality of the ScrollViewer control. If you have any other questions or concerns and have not yet downloaded the source code for this project, I strongly suggest doing so. Seeing it in its entirety can help clear up many of your questions. Thank you for your time and I hope this has been helpful, take care.

We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!

WP7ScrollViewerTut.zip