Similar to the Hello Location
application that we saw in Chapter 2, Using Location in Windows Phone 7.5, we will now create a new application titled HelloMaps
that shows the Windows Phone Bing Maps Silverlight Control in action:
HelloMaps
. Hello Maps
and the Page Title to Bing Maps
. Your project should now look like the following screenshot:Invalid Credentials. Sign up for a developer account at:
http://www.microsoft.com/maps/developers
xxxxxxxxxxxxxx
as the key) let us initialize our Map control with the same.<my:Map>
when you added the Map control to your application. Add the key we got from step 7 by using the CredentialsProvider
attribute of the Bing Maps Silverlight Control. Also change the name of the map to"myMap"
.<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<my:Map Height="595"
CredentialsProvider="xxxxxxxxxxxxxx"
HorizontalAlignment="Left" Margin="6,6,0,0" Name="myMap"
VerticalAlignment="Top" Width="444" />
</Grid>
Hello Maps
application that will allow us to choose the map mode: Road Mode or Aerial Mode. MainPage.xaml
uncomment the following lines that add a default application bar to your application:<!--Sample code showing usage of ApplicationBar--> <!--<phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/> <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> <shell:ApplicationBar.MenuItems> <shell:ApplicationBarMenuItem Text="MenuItem 1"/> <shell:ApplicationBarMenuItem Text="MenuItem 2"/> </shell:ApplicationBar.MenuItems> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>-->
<phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBar.MenuItems> <shell:ApplicationBarMenuItem Text="Aerial Mode"/> <shell:ApplicationBarMenuItem Text="Road Mode"/> </shell:ApplicationBar.MenuItems> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>
Aerial Mode
Application Bar Menu Item and before the Text
property enter Click=""
. IntelliSense will prompt you<New Event Handler>
as shown in the following screenshot. Select it.<shell:ApplicationBarMenuItem Click="ApplicationBarMenuItem_Click" Text="Aerial Mode"/> <shell:ApplicationBarMenuItem Click="ApplicationBarMenuItem_Click_1" Text="Road Mode"/>
MainPage.xaml.cs
file and you will find the two click event functions created automatically: ApplicationBarMenuItem_Click
and ApplicationBarMenuItem_Click_1
. ApplicationBarMenuItem_Click
function:private void ApplicationBarMenuItem_Click(object sender, EventArgs e) { myMap.Mode = new AerialMode(); }
myMap
variable was assigned to the Map control in step 8. ApplicationBarMenuItem_Click_1
function, however here we set the mode to Road by using the following code:private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e) { myMap.Mode = newRoadMode(); }
You can find this example project in the code files for the book under Chapter 3, titled HelloMaps
.
3.142.255.225