A group blog from members of the VB team
Previously, I explained how to create a keyboard input scope application for Windows Phone 7. In this blog post, I want to share a sample that will help you to create a panorama and pivot effect in Windows Phone 7. A Panorama is any wide-angle view or representation of a physical space, whether in painting, drawing, photography, or a three-dimensional model. This feature allows you to view controls, data, and services by using a long horizontal canvas that extends beyond the confines of the screen. A Pivot is a page orientation in which a rectangular page is oriented for normal viewing. It helps you to easily manage views or pages. In this application, I will demonstrate how to create both panoramic and pivot experience for Windows Phone 7. Sounds interesting? So let’s begin.
But hey, wait a minute! Before you create the panorama and pivot effect application, you need to install the following applications:
The panorama and pivot effect can be created in 7 easy steps as follows:
<Button Content="Panorama Experience" Height="168"HorizontalAlignment="Left" Margin="35,82,0,0" Name="btnPanorama"VerticalAlignment="Top" Width="383" Click="btnPanorama_Click" />
<Button Content="Pivot Experience" Height="168"HorizontalAlignment="Left" Margin="35,297,0,0" Name="btnPivot"VerticalAlignment="Top" Width="383" Click="btnPivot_Click" />
It is essential to add an event handler to the application because it helps to navigate to the panorama or the pivot screen depending on the button clicked.
To add an event handler, do the following:
PrivateSubbtnPanorama_Click(ByVal sender AsSystem.Object,
ByVal e AsSystem.Windows.RoutedEventArgs)
NavigationService.Navigate(NewUri("/PanoramaPage1.xaml", UriKind.Relative))
EndSub
PrivateSubbtnPivot_Click(ByVal sender AsSystem.Object,
NavigationService.Navigate(NewUri("/PivotPage1.xaml", UriKind.Relative))
<!--Pivot Control-->
<controls:Pivot Title="PIVOT CONTROL">
<!--Pivot item one-->
<controls:PivotItem Header="item1">
<Grid>
</Grid>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="item2">
<!--Pivot item three-->
<controls:PivotItem Header="item3">
</controls:Pivot>
<!--Added textbox control with formatted text-->
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextLargeStyle}">
<Run>This is a simple sample for the pivot control adding text.</Run>
<LineBreak/>
<Run>You can put any content you want here...</Run>
</TextBlock>
To create second pivot item, add the following XAML code after the <controls:PivotItem Header="item2"> tag.
<!--Added background image and text content--> <Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="{StaticResource PhoneBorderThickness}"> <Grid> <Image Source="samplePhoto.jpg" Stretch="UniformToFill"/> <TextBlock Text="Here is some generic content to take up space." TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" /> </Grid> </Border>
<!--Added background image and text content-->
<Border
BorderBrush="{StaticResource PhoneForegroundBrush}"
BorderThickness="{StaticResource PhoneBorderThickness}">
<Image
Source="samplePhoto.jpg"
Stretch="UniformToFill"/>
Text="Here is some generic content to take up space."
Style="{StaticResource PhoneTextExtraLargeStyle}" />
</Border>
Note: This method adds an assortment of content including a background image and wrapping text.
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<!--This code is a series of string text values-->
<ListBox FontSize="{StaticResource PhoneFontSizeLarge}">
<sys:String>This</sys:String>
<sys:String>item</sys:String>
<sys:String>has</sys:String>
<sys:String>a</sys:String>
<sys:String>short</sys:String>
<sys:String>list</sys:String>
<sys:String>of</sys:String>
<sys:String>strings</sys:String>
<sys:String>that</sys:String>
<sys:String>you</sys:String>
<sys:String>can</sys:String>
<sys:String>scroll</sys:String>
<sys:String>up</sys:String>
<sys:String>and</sys:String>
<sys:String>down</sys:String>
<sys:String>back</sys:String>
<sys:String>again.</sys:String>
</ListBox>
<Grid x:Name="LayoutRoot">
<controls:Panorama Title="my pano">
<!--Panorama item one-->
<controls:PanoramaItem Header="item1">
</controls:PanoramaItem>
<!--Panorama item two-->
<controls:PanoramaItem Header="item2">
</controls:Panorama>
<!--Panorama item three-->
<controls:PanoramaItem Header="item3"
To set the background image, add the following XAML after the <controls:Panorama Title="my application"> tag:
<!--Assigns a background image to the Panorama control-->
<controls:Panorama.Background>
<ImageBrushImageSource="samplePhoto.jpg"/>
</controls:Panorama.Background>
Note: This method sets the background image to the default “samplePhoto.jpg” image. You can set any other image as the background as well. The recommended dimensions for a background image is a height of 800 pixels and a width less than 2000 pixels. At a width of 2000 pixels, the picture will be clipped. If your image does not have a height of 800 pixels, it will be stretched to that height without preserving the aspect ratio.
<!--This code creates two TextBlock controls and places them in a StackPanel control-->
<StackPanel>
Text="This is a text added to the first panorama item control"
Style="{StaticResourcePhoneTextLargeStyle}"
TextWrapping="Wrap"/>
<TextBlock Text=" "/>
Text="You can put any content you want here..."
</StackPanel>
<controls:PanoramaItem Header="item2" Orientation="Horizontal">
<!-- Assigns a border to the PanoramaItem control and background for the content section. -->
BorderBrush="{StaticResourcePhoneForegroundBrush}"
BorderThickness="{StaticResourcePhoneBorderThickness}"
Background="#80808080">
Text="This content is very wide and can be panned horizontally."
Style="{StaticResourcePhoneTextExtraLargeStyle}"
HorizontalAlignment="Center"
VerticalAlignment="Center" >
<ListBoxFontSize="{StaticResourcePhoneFontSizeLarge}">
There you are! Now your panorama and pivot effect application for Windows Phone 7 is ready! You just need to build and debug the application.
Note: To stop debugging the application, select Debug > Stop Debugging.
Finally, to submit your application to the market place, you can refer to upload your application walkthrough.
Voila! Wasn’t that fun? You have successfully created a panorama and a pivot effect application for Windows Phone 7, that too in just 7 steps! It’s very easy, right? I am sure you must have enjoyed a lot creating this application.
You can find the full source code for the panorama and a pivot effec application here. This application uses general Silverlight and Visual Basic features that are applicable for different application types including Windows Phone application.