Windows Phone 7 ScrollViewer Control
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.
<ScrollViewer Height="218" HorizontalAlignment="Left" Margin="18,0,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="450" HorizontalScrollBarVisibility="Auto" Grid.Row="1">
</ScrollViewer>
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.
<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>
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.
<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>
We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!
WP7ScrollViewerTut.zip