Hands-On Lab. Using Bing Maps

Size: px
Start display at page:

Download "Hands-On Lab. Using Bing Maps"

Transcription

1 Hands-On Lab Using Bing Maps Lab version: Last updated: 2/2/2011

2 CONTENTS Overview... 3 Exercise 1: Introduction to the Bing Map Control... 7 Task 1 Registering a Bing Maps Account... 7 Task 2 Working with the Bing Map Control Exercise 2: Handling and Customizing Pushpins Task 1 Creating a Pushpins Layer Task 2 Creating a Pushpins Catalog Exercise 3: Calculating a Route Task 1 Adding a Route to the Map Task 2 Displaying Route Itineraries Summary Page 2

3 Overview The Bing Maps Silverlight Control for Windows Phone combines the power of Silverlight and Bing Maps to provide an enhanced mapping experience. Developers can use the Bing Maps Silverlight Control to incorporate the latest location and local search features into their Windows Phone applications. Using both Bing Maps Silverlight Control and the Bing Maps SOAP (strategy on a page) Services, you can create Windows Phone applications that include an enhanced mapping experience. This lab walks you through the steps required for using the Bing Maps Silverlight Control for Windows Phone, and provides a quick reference for developing Windows Phone applications integrated with Bing Maps. Objectives Upon completion of the lab you will: Be familiar with Bing Maps for Windows Phone Understand how to use Bing Map control with Data Binding Have used Bing Maps services to fetch mapping data Have created a simple map-based application, complete with pushpins and route layers Prerequisites The following is required to complete this hands-on lab: Microsoft Visual Studio 2010 Express for Windows Phone or Microsoft Visual Studio 2010 Windows Phone Developer Tools Active Internet Connection Note: You can download all Windows Phone development tools in one package from Setup For your convenience, much of the code used in this hands-on lab is available as Visual Studio code snippets. Page 3

4 To install the code snippets: 1. Run the.vsi installer located in the lab's Source\Setup folder. Note: If you have issues running the code snippets installer you can install the code snippets manually by copying all the.snippet files located in the Source\Setup\CodeSnippets folder of the lab to the following folder: <your-documents-folder>\visual Studio 2010\Code Snippets\Visual \My Code Snippets Using the Code Snippets With code snippets, you have all the code you need at your fingertips. The lab document will tell you exactly when you can use them. For example, Figure 1 Using Visual Studio code snippets to insert code into your project To add this code snippet in Visual Studio, you simply place the cursor where you would like the code to be inserted, start typing the snippet name (without spaces or hyphens), watch as IntelliSense picks up the snippet name, and then press the Tab key twice when the snippet you want is selected. The code will be inserted at the cursor location. Page 4

5 Figure 2 Start typing the snippet name Figure 3 Press Tab to select the highlighted snippet Figure 4 Press Tab again to expand the snippet To insert a code snippet using the mouse rather than the keyboard, right-click where you want to insert the code snippet, select Insert Snippet followed by My Code Snippets and then pick the relevant snippet from the list. To learn more about Visual Studio IntelliSense Code Snippets, including how to create your own, see Exercises This hands-on lab comprises the following exercises: 1. Introduction to the Bing Map Control Page 5

6 2. Handling and Customizing Pushpins 3. Calculating and Rendering a Route Estimated time to complete this lab: 90 minutes. Page 6

7 Exercise 1: Introduction to the Bing Map Control In this exercise you will: Register a Bing Maps account to get a private key Learn about the Bing Silverlight map control for Windows Phone Add a map control to the page Attach the map control with Bing Maps private key Switch between aerial and road map modes Center and zoom the map to a geographic location You will use the Microsoft Visual Studio 2010 Express for Windows Phone development environment, and will deploy to the Windows Phone Emulator for debugging. The solution we will be working with is based upon the Silverlight for Windows Phone Application template. Note: The steps in this hands-on lab illustrate procedures using Microsoft Visual Studio 2010 Express for Windows Phone, but they are equally applicable to Microsoft Visual Studio 2010 with the Windows Phone Developer Tools. Instructions that refer generically to Visual Studio apply to both products. Task 1 Registering a Bing Maps Account In this task you will create a Bing Maps account over the Internet. The Bing Maps Account Center allows you to create keys to use the Bing Maps Control, Bing Maps SOAP Services, Bing Maps REST (representational state transfer) Services and Bing Spatial Data Services. If you already have a key for using Bing, you may use it for the next tasks. Without a valid key, you won t be able to see retrieve Bing Maps content from the web. 1. Open your web browser and go to the following address: 2. Click Create to create a new Bing Maps account using your Windows Live ID. Page 7

8 Figure 5 Bing maps registration 3. On the next page, fill in your details. Figure 6 Bing maps account details 4. Once you ve agreed the terms and registered and/or signed in, you may choose to create a new key for your application. Click the Create or view keys link on the left. Page 8

9 Figure 7 Create or view keys 5. On the next page fill in your application details and click Createkey. Figure 8 Create a new key Page 9

10 6. Below, you ll see your new private key. Save this key, you will use it later. Figure 9 Saving the private key Note: In the next tasks you ll be asked to use this private key. Keep it handy since you ll have to use it for the rest of this lab. Task 2 Working with the Bing Map Control In this task you ll use the Bing Map Silverlight control for Windows Phone. The Bing Map Silverlight Control combines the power of Silverlight and Bing Maps to provide an enhanced mapping experience. Developers can use the Bing Maps Silverlight Control to incorporate the latest location and local search features into their applications. You ll use an existing starter solution for Microsoft Visual Studio 2010 Express for Windows Phone or Microsoft Visual Studio This solution contains a partial Windows Phone application, with startup code and UI behavior for completing this lab. 1. Open Microsoft Visual Studio 2010 Express for Windows Phone from Start All Programs Microsoft Visual Studio 2010 Express Microsoft Visual Studio 2010 Express for Windows Phone. 2. In the File menu, choose Open Project. Visual Studio 2010: In the File menu, point to open and then select Project/Solution. Page 10

11 3. Navigate to the starter project location at the Source\Ex1-TheBingMapControl\Begin folder of this lab, select Begin.sln and click Open. Figure 10 Opening starter project 4. Examine the project you ve just opened. This is a standard Windows Phone application consists of single page: MainPage: MainPage.xaml defines the Bing maps lab UI using ; you ll place UI controls into this file during the lab MainPage.cs this is a partial class that contains startup code for implementing the Bing maps lab; do not change this file during the lab MainPage.xaml.cs contains the map lab logic; you ll place map application logic in this file during the lab o o Resources such as icons and styles are located in the Resources folder Helper classes are placed in the Helpers folder Page 11

12 5. To run the startup application, press F5. You should see the following: Figure 11 Running the starter application Page 12

13 6. During the following steps you will use the Bing map control and learn how to use it. To begin, add a reference to the Microsoft.Phone.Controls.Maps assembly. Figure 12 Add reference to map controls assembly Page 13

14 7. Open the MainPage.xaml in design mode and drag the Map control, located on the toolbox, to the center of the page. This will both add an namespace and create an instance of the Bing map control for Windows Phone. Figure 13 Map control design time 8. Open MainPage.xaml with the editor, you should find something like this: <!-- Map View --> <Border x:name="mapview" Background="Black" Height="768" Width="480"> <my:map Name="map1" Height= 50 Width= 50 /> Page 14

15 </Border> 9. Change the map name to Map and remove both Height and Width properties so the map will stretch across the entire screen. <my:map x:name="map" /> 10. Press F5 to examine the map. Figure 14 Bing map control Page 15

16 Note: The first time you zoom in by double clicking the map, the following message appears: Invalid Credentials. Sign up for a developer account. To remove this message, you should use the Bing Maps private key created earlier with the map. 11. Open the App.xaml.cs file and add a new internal constant string field called Id to the App class. This field will hold the Bing Maps private key you ve created. You will reference this key during the lab to create credentials for both the Bing map control and Bing services. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 11 Id Const) internal const string Id = "your Bing maps private key"; 12. Open the MainPage.xaml.cs file and add the following using statements above the class declaration. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 12 Using statements) using System; using System.Device.Location; using Microsoft.Phone.Controls.Maps; 13. Now that we have the private key, we want to bind the map control with that key. To do so: Locate the Fields region inside the MainPage class Create a new private read-only field of type Microsoft.Phone.Controls.Maps.CredentialsProvider Initialize it with a new instance using the private key you ve just added to the App class (Code Snippet Using Bing Maps Ex 1 Task 2 Step 13 CredentialsProvider Field) private readonly CredentialsProvider _credentialsprovider = new ApplicationIdCredentialsProvider(App.Id); Note: If the using statement for the Microsoft.Phone.Controls.Maps were not added, you should resolve this issue by either using a full qualified class name or adding the required using statement. Several code snippets in this lab assume you are aware of how to resolve this kind of inconveniences. Page 16

17 14. Locate the Properties region inside the MainPage class and expose the field you ve just created as a public property called CredentialsProvider so you can bind it with the map control. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 14 CredentialsProvider Property) public CredentialsProvider CredentialsProvider get return _credentialsprovider; 15. Open the MainPage.xaml file in editor, and bind the Map.CredentialsProvider property with the public property you ve just created. <my:map Name="Map" CredentialsProvider="Binding CredentialsProvider" /> Note: The MainPage.DataContext is set with the MainPage instance itself in the MainPage.cs file, so the implicit binding source is the MainPage instance itself. 16. Press F5 again to test the application. Zooming in, you should notice that the message that appeared previously has gone. 17. Open the MainPage.xaml file in mode, and set the Map.Mode property to AerialMode with labels. This will change the map mode to be displayed in aerial view rather than road view, which is the default. <my:map Name="Map" CredentialsProvider="Binding CredentialsProvider"> <my:map.mode> <my:aerialmode ShouldDisplayLabels="True" /> </my:map.mode> </my:map> 18. We ve added a button to the application bar for changing the map mode. This button s click event is handled by calling the ChangeMapMode method located in the Tasks region. In the MainPage.xaml.cs, locate the Tasks region inside the MainPage class. You ll find the ChangeMapMode method over there. Place code for switching from Page 17

18 Road to Aerial mode and vice versa, by setting the Map.Mode property with a new instance of type Microsoft.Phone.Controls.Maps.AerialMode or Microsoft.Phone.Controls.Maps.RoadMode. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 18 ChangeMapMode) private void ChangeMapMode() if (Map.Mode is AerialMode) Map.Mode = new RoadMode(); else Map.Mode = new AerialMode(true); Page 18

19 19. Press F5 to test the results. For switching views, click on the eye button on the application bar. This invokes the ChangeMapMode method. Figure 15 Aerial map mode Page 19

20 Figure 16 Road map mode Note: The Silverlight Map control for Windows Phone is designed to support the data binding model. Changing properties of the Map control using data binding is a good way for handling data objects within data templates and is a best practice for decoupling the Map control from the logic behind, especially when using the MVVM (model view viewmodel) pattern. For the simplicity of this lab, we are not using a data template for the map view itself; hence the logic is located directly in the MainView code behind. From now on, we will leverage the map control data binding capabilities, although properties of the map control can be altered directly from code behind. Page 20

21 20. To remove the Bing logo and Copyright from the bottom, you can set both Map.CopyrightVisibility and Map.LogoVisibility to Visibility.Collapsed. <my:map Name="Map" CredentialsProvider="Binding CredentialsProvider" CopyrightVisibility="Collapsed" LogoVisibility="Collapsed"> <my:map.mode> <my:aerialmode ShouldDisplayLabels="True" /> </my:map.mode> </my:map> You may notice that you can zoom in by double-clicking on the map. This option is implemented internally by the map control. You have an option to display the built-in zoom bar, by setting the Map.ZoomBarVisibility to Visible, but you can t change the buttons style or location. Next you will add custom zoom buttons so you can freely zoom in and out. 21. In the MainPage.xaml.cs, add a new private field of type double. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 21 Zoom Field) private double _zoom; 22. Find the Consts region and add three additional constant double fields to constraint the zoom level: DefaultZoomLevel = 18.0 MaxZoomLevel = 21.0 MinZoomLevel = 1.0. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 22 Zoom Level Consts) private const double DefaultZoomLevel = 18.0; private const double MaxZoomLevel = 21.0; private const double MinZoomLevel = 1.0; Page 21

22 23. In MainPage.xaml.cs, find the automatic property called Zoom, and change it to get or set the value of the _zoom field. In the setter, consider the zoom level constraints you ve added and notify on property changed. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 23 Zoom Property) public double Zoom get return _zoom; set var coercedzoom = Math.Max(MinZoomLevel, Math.Min(MaxZoomLevel, value)); if (_zoom!= coercedzoom) _zoom = value; NotifyPropertyChanged("Zoom"); 24. Open the MainPage.xaml in editor and bind the Map.ZoomLevel property with the Zoom property you ve just changed. The binding mode must be two-way. <my:map Name="Map" LogoVisibility="Collapsed" ZoomLevel="Binding Zoom, Mode=TwoWay"> <my:map.mode> <my:aerialmode ShouldDisplayLabels="True" /> </my:map.mode> </my:map> 25. Drop two buttons vertically from the toolbox into the middle left side of the map control, one for zoom-in and the other for zoom-out. <my:map Name="Map" LogoVisibility="Collapsed" ZoomLevel="Binding Zoom, Mode=TwoWay"> <my:map.mode> <my:aerialmode ShouldDisplayLabels="True" /> Page 22

23 </my:map.mode> <Button x:name="buttonzoomin" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,180,0,0" /> <Button x:name="buttonzoomout" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,260,0,0" /> </my:map> 26. Register the respective button Click event with the ButtonZoomIn_Click and ButtonZoomOut_Click event handlers. These event handlers are already provided in the MainView.cs file. When invoked, the ButtonZoomIn_Click event handler increases the Zoom property by one and the ButtonZoomOut_Click event handler decreases the Zoom property by one. <Button x:name="buttonzoomin" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,180,0,0" Click="ButtonZoomIn_Click" /> <Button x:name="buttonzoomout" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,260,0,0" Click="ButtonZoomOut_Click" /> 27. To change the look and feel of the zoom-in and zoom-out buttons, open the MainView.xaml in mode and set each Button.Style property with the appropriate ButtonZoomInStyle or ButtonZoomOutStyle style. These styles were provided with the starter solution and are located in the DefaultStyle.xaml resource file. <Button x:name="buttonzoomin" Style="StaticResource ButtonZoomInStyle" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,180,0,0" Click="ButtonZoomIn_Click" /> <Button x:name="buttonzoomout" Style="StaticResource ButtonZoomOutStyle" HorizontalAlignment="Left" VerticalAlignment="Top" Page 23

24 Height="56" Width="56" Margin="8,260,0,0" Click="ButtonZoomOut_Click" /> 28. To test the results, press F5 and click the zoom-in and zoom-out buttons. Figure 17 Zoom out Page 24

25 Figure 18 Zoom in In the next step you ll center the map to your geographic location. Since this lab works with the emulator, you don t have a real GPS device. So you ll have to pre-define your geographic location using latitude and longitude coordinates. Note: You can determine your geographic location by browsing to set your location, and then copy the Latitude and Longitude coordinates from the address bar. Page 25

26 29. Add a reference to the System.Device assembly. Figure 19 Reference System.Device 30. In the MainPage.xaml.cs, add a new static, read-only field of type System.Device.Location.GeoCoordinate, called DefaultLocation, and set it with a new instance using your latitude and longitude coordinates. This will be your current location. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 30 DefaultLocation Field) private static readonly GeoCoordinate DefaultLocation = new GeoCoordinate( , ); 31. In the MainPage.xaml.cs, add a new field of type System.Device.Location.GeoCoordinate, called _center. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 31 Center Field) private GeoCoordinate _center; Page 26

27 32. Create a property called Center that exposes the _center field. In the setter, call the notification change method. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 32 Center Property) public GeoCoordinate Center get return _center; set if (_center!= value) _center = value; NotifyPropertyChanged("Center"); 33. In the MainPage.xaml, bind the Map.Center property with the Center property you ve created. The binding mode must be two-way. <my:map Name="Map" CredentialsProvider="Binding CredentialsProvider" ZoomLevel="Binding Zoom, Mode=TwoWay" Center="Binding Center, Mode=TwoWay">... </my:map> 34. In the MainPage.xaml.cs, find the CenterLocation method. The first application s bar left button event handler calls this method. Change both Center and Zoom to defaults. (Code Snippet Using Bing Maps Ex 1 Task 2 Step 34 CenterLocation Method) private void CenterLocation() Center = DefaultLocation; Zoom = DefaultZoomLevel; Page 27

28 35. To test the application, press F5 and click the application bar s target icon on the left. This should zoom and center the map to the location provided by the DefaultLocation field. Figure 20 Center and zoom map to default location This concludes the exercise. Note: The complete solution for this exercise is provided at the following location: Source\Ex1-TheBingMapControl\End. Page 28

29 Page 29

30 Exercise 2: Handling and Customizing Pushpins In this exercise you will: Learn how to use map layers with data binding Create a pushpin layer Add a pushpin for indicating current location Handle pushpin clicks Add pushpins from a catalog to the map Customize the pushpin look and feel You will use the Microsoft Visual Studio 2010 Express for Windows Phone development environment, and will deploy to the Windows Phone Emulator for debugging. The solution we will be working with is based upon the previous exercise. Task 1 Creating a Pushpins Layer In this task you will learn how to create a map layer and how to populate it with pushpin data using data binding. A map layer is represented by a custom panel of type Microsoft.Phone.Controls.Maps.MapLayer. Using the MapLayer panel you can have any kind of UIElement on top of the map. The MapLayer panel knows how to lay out elements on the map using geo coordinates. A map control can have zero or more layers. Although we can add and remove visual items directly to the MapLayer panel from code behind, we will populate map layers using the data binding mechanism. Instead of using MapLayer directly, we will use another control of type Microsoft.Phone.Controls.Maps.MapItemsControl. This custom ItemsControl uses the MapLayer panel to layout items by default. 1. Open the starter solution located in the Source\Ex2-HandlingPushpins\Begin folder. Note: You should set the Bing Maps application Id in the App class with your private key created in the previous exercise. 2. To add a new pushpins layer to the map, open the MainPage.xaml in editor and add a new MapItemsControl element as a child of the map control, just before the zoom buttons so the buttons will render on top. This will be our pushpins layer. <my:map Name="Map" CredentialsProvider="Binding CredentialsProvider" ZoomLevel="Binding Zoom, Mode=TwoWay" Page 30

31 Center="Binding Center, Mode=TwoWay"> <my:map.mode> <my:aerialmode ShouldDisplayLabels="True" /> </my:map.mode> <my:mapitemscontrol /> <Button x:name="buttonzoomin" Style="StaticResource ButtonZoomInStyle" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,180,0,0" Click="ButtonZoomIn_Click" /> <Button x:name="buttonzoomout" Style="StaticResource ButtonZoomOutStyle" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56" Width="56" Margin="8,260,0,0" Click="ButtonZoomOut_Click" /> </my:map> 3. To populate the new pushpins layer with pushpins data, create a new project folder called Models. 4. Under the Models folder, create a new public class called PushpinModel. This class represents the pushpin data. Figure 21 Pushpin model Page 31

32 5. Add a new automatic public property called Location of type System.Device.Location.GeoCoordinate to the PushpinModel. This property indicates the pushpin s geographical location on the map. (Code Snippet Using Bing Maps Ex 2 Task 1 Step 5 Location Property) public class PushpinModel public GeoCoordinate Location get; set; 6. To populate the pushpins layer with pushpins, add a new private read-only field called _pushpins of type ObservableCollection<PushpinModel> to MainPage.xaml.cs, and initialize it with one PushpinModel instance using the default location. (Code Snippet Using Bing Maps Ex 2 Task 1 Step 6 Pushpins Field) private readonly ObservableCollection<PushpinModel> _pushpins = new ObservableCollection<PushpinModel> new PushpinModel Location = DefaultLocation ; 7. Expose the _pushpins field with public property so you can bind it with the pushpins layer. (Code Snippet Using Bing Maps Ex 2 Task 1 Step 7 Pushpins Property) public ObservableCollection<PushpinModel> Pushpins get return _pushpins; 8. Open the MainPage.xaml in editor and bind the MapItemsControl you ve added with the Pushpins collection. Page 32

33 <my:mapitemscontrol ItemsSource="Binding Pushpins" /> 9. If you run the application, you ll notice that the pushpin data is added to the map s top left corner as a text block. You can change that by simply creating a data template. To create a data template, set the MapItemsControl.ItemTemplate property with a DataTemplate element that contains one Pushpin. <my:mapitemscontrol ItemsSource="Binding Pushpins"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin /> </DataTemplate> </my:mapitemscontrol.itemtemplate> </my:mapitemscontrol> 10. In order to place the pushpin at the exact location on the map, bind the Pushpin.Location property with the Location property of the PushpinModel. <my:mapitemscontrol ItemsSource="Binding Pushpins"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin Location="Binding Location" /> </DataTemplate> </my:mapitemscontrol.itemtemplate> </my:mapitemscontrol> 11. Set the Pushpin.Content property to My Location. <my:pushpin Location="Binding Location" Content="My Location" /> Page 33

34 12. Press F5 to test the results. You should see a black pushpin with a text label. This is the pushpin you ve just added with a default black style. If you click on the current location icon on the application bar, the map will center on the default location and you ll see the pushpin in the center. Figure 22 Pushpin default style 13. A pushpin can be customized easily. It is a ContentControl; hence we can change its style and control template. To create a new pushpin style and control template, open Page 34

35 the DefaultStyle.xaml resource dictionary located in the Resources/Styles project folder and map the Bing maps control namespace. <ResourceDictionary... xmlns:m="clrnamespace:microsoft.phone.controls.maps;assembly=microsoft.phone.control s.maps"> <!-- Next step, pushpin style comes here --> </ResourceDictionary> 14. Inside the DefaultStyle.xaml resource dictionary, create a new style for the pushpin as follows: <Style x:key="pushpinstyle" TargetType="m:Pushpin"> <Setter Property="BorderBrush" Value="#FFF4F4F5" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Canvas Height="0" RenderTransformOrigin="0.5,0.5" Width="0"> <Canvas RenderTransformOrigin="0.5,0.5" Height="1" Width="1"> <Path Data="M22.5,1 C ,1 44, ,22.5 C44, , , L , L , L , L , C , , ,22.5 C , ,1 22.5,1 z" Fill="TemplateBinding BorderBrush" Height="61.865" Stretch="Fill" Stroke="Black" StrokeThickness="2" StrokeLineJoin="Miter" UseLayoutRounding="False" Width="45" RenderTransformOrigin="0.5,0.5" Canvas.Left="-2.703" Canvas.Top="-7.187" > <Path.RenderTransform> <CompositeTransform TranslateX="-20" Page 35

36 TranslateY="-55"/> </Path.RenderTransform> </Path> <Path Data="M35,17.5 C35, , ,35 C ,35 0, ,17.5 C0, ,0 17.5,0 C ,0 35, ,17.5 z" Fill="TemplateBinding Background" HorizontalAlignment="Left" Height="35" Stretch="Fill" StrokeThickness="2" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="35" UseLayoutRounding="False" Canvas.Top="-7.4" Canvas.Left="-2.888" > <Path.RenderTransform> <CompositeTransform TranslateX="-15" TranslateY="-50"/> </Path.RenderTransform> </Path> </Canvas> <ContentPresenter Width="35" Height="35" RenderTransformOrigin="0.5,0.5" Canvas.Top="-3.5"> <ContentPresenter.RenderTransform> <CompositeTransform TranslateX="-18" TranslateY="-54"/> </ContentPresenter.RenderTransform> </ContentPresenter> </Canvas> </ControlTemplate> </Setter.Value> </Setter> </Style> Note: If you design your own pushpin control template, you should know that the default relative point of a pushpin when scaling the map (zoom) is the bottom left corner, not the center or top left. You can easily create your own control template using Microsoft Expression Blend for Windows Phone, which is part of the Windows Phone development tools. 15. Add new public property of type Uri, named Icon to the PushpinModel. You will use it to bind the image of the pushpin. Page 36

37 (Code Snippet Using Bing Maps Ex 2 Task 1 Step 15 Icon Property) public class PushpinModel public GeoCoordinate Location get; set; public Uri Icon get; set; 16. Under the Resources\Icons folder, create a new folder called Pushpins, and add all images from the Source\Assets\Resources\Pushpins folder. Figure 23 Pushpin images Page 37

38 17. Change each of the images build actions from Resource to Content. To do so, select all pushpin images, right click, select properties, and change the Build Action to Content. Figure 24 Changing pushpin images build action to Content 18. In the MainPage.xaml, set the style of the pushpin to the one you ve added. <my:mapitemscontrol ItemsSource="Binding Pushpins"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin Style="StaticResource PushpinStyle" Location="Binding Location" /> </DataTemplate> </my:mapitemscontrol.itemtemplate> </my:mapitemscontrol> 19. Set the content of the pushpin to an Image element and bind the Image.Source property to the PushpinModel.Icon property. <my:mapitemscontrol ItemsSource="Binding Pushpins"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin Style="StaticResource PushpinStyle" Location="Binding Location"> <Image Source="Binding Icon" /> </my:pushpin> </DataTemplate> </my:mapitemscontrol.itemtemplate> Page 38

39 </my:mapitemscontrol> 20. In the MainPage.xaml.cs, set the PushpinData.Icon property of pushpin instance you ve created before with a relative Uri to the PushpinLocation.png icon file located in the Pushpins project folder. (Code Snippet Using Bing Maps Ex 2 Task 1 Step 20 Pushpin Icon Value) private readonly ObservableCollection<PushpinModel> _pushpins = new ObservableCollection<PushpinModel> new PushpinModel Location = DefaultLocation, Icon = new Uri("/Resources/Icons/Pushpins/PushpinLocation.png", UriKind.Relative) ; Page 39

40 21. Press F5 to see the results. You should observe that the pushpin s default black style has changed, and now it looks like the pushpin in Bing maps over the web. Figure 25 Custom pushpin style Task 2 Creating a Pushpins Catalog In this task you ll create a pushpin catalog and display it using a popup window. To build a catalog, you will bind a list box to a collection of predefined pushpin models. Selecting a pushpin Page 40

41 from the catalog will clone it and add that pushpin to the touched area. You will use the Map control APIs to translate a view point to geographic location. 1. Add a new public property of type string, named TypeName to the PushpinModel class you ve created, located in the Models project folder. You ll use this type name to pick a different color for different types of pushpins. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 1 TypeName Property) public class PushpinModel public GeoCoordinate Location get; set; public Uri Icon get; set; public string TypeName get; set; 2. Add the PushpinCatalog.cs file located in the Source\Assets\Code folder to the Models project folder. This file defines a class which contains one pushpin instance per pushpin type. public class PushpinCatalog private List<PushpinModel> _items; public IEnumerable<PushpinModel> Items get return _items; public PushpinCatalog() InitializePuspins(); private void InitializePuspins() string[] pushpinicons = "PushpinBicycle.png", "PushpinCar.png", "PushpinDrink.png", "PushpinFuel.png", "PushpinHouse.png", Page 41

42 ; "PushpinRestaurant.png", "PushpinShop.png" var pushpins = from icon in pushpinicons select new PushpinModel Icon = new Uri("/Resources/Icons/Pushpins/" + icon, UriKind.Relative), TypeName = System.IO.Path.GetFileNameWithoutExtension(icon) ; _items = pushpins.tolist(); 3. In the MainPage.xaml, find the PushpinPopup popup element and add a ListBox named ListBoxPushpinCatalog as its only child. <Popup x:name="pushpinpopup" IsOpen="False" Canvas.Top="330" Canvas.Left="25" Opacity="0"> <ListBox x:name="listboxpushpincatalog" /> </Popup> 4. Set the following ListBox properties: <ListBox x:name="listboxpushpincatalog" Width="392" Height="56" Background="StaticResource ControlBackgroundBrush"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> 5. To create an instance of the catalog and bind the list box with the catalog s items, map the UsingBingMaps.Models CLR namespace using xmlns. <phone:phoneapplicationpage x:class="usingbingmaps.mainpage" Page 42

43 ... xmlns:models="clr-namespace:usingbingmaps.models">... </phone:phoneapplicationpage> 6. Set the ListBox.DataContext property with a fresh instance of type PushpinCatalog and bind the list box with the PushpinCatalog.Items. <ListBox x:name="listboxpushpincatalog" Width="392" Height="56" Background="StaticResource ControlBackgroundBrush" ItemsSource="Binding Items"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.DataContext> <models:pushpincatalog /> </ListBox.DataContext> </ListBox> 7. Create a list box item template which has a single instance of type Image. Bind the Image.Source to the PushpinModel.Icon property, and set the image size to 56x56. <ListBox.ItemTemplate> <DataTemplate> <Image Width="56" Height="56" Source="Binding Icon" /> </DataTemplate> </ListBox.ItemTemplate> 8. To center the popup at the exact touch location, find the CenterPushpinsPopup method located in the MainPage.xaml.cs file, and add logic to calculate the popup s Canvas.Top value based on the size of the list box and the touch point. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 8 Canvas SetTop) private void CenterPushpinsPopup(Point touchpoint) Canvas.SetTop(PushpinPopup, touchpoint.y - ListBoxPushpinCatalog.Height / 2); Page 43

44 9. To see the results, press F5. When the map loaded, press and hold the left mouse button on the map. This should open the popup. This behavior already exists as part of the starter solution. Figure 26 Pushpin catalog Page 44

45 10. Now that the catalog is ready, let s add logic to pick a pushpin and place it at the exact location. Register the ListBox.SelectionChanged event with the ListBoxPushpinCatalog_SelectionChanged event handler provided with the starter solution. 11. Add a new method named Clone to the PushpinModel class. This method should return a clone of the PushpinModel instance with a different geo location provided as parameter of type GeoCoordinate. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 11 Clone Method) public PushpinModel Clone(GeoCoordinate location) return new PushpinModel Location = location, TypeName = TypeName, Icon = Icon ; 12. In the MainPage.xaml.cs, find the CreateNewPushpin method. This method is called by the ListBoxPushpinCatalog_SelectionChanged located in the MainPage.cs. It has two parameters: the selected pushpin model and the exact touch point in view coordinates. Translate the touch point to geo coordinates using the Map.TryViewportPointToLocation method. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 12 Translate Location) private void CreateNewPushpin(object selecteditem, Point point) GeoCoordinate location; Map.TryViewportPointToLocation(point, out location); 13. Now that you ve got the exact geo coordinate for the pushpin, clone the selected pushpin with the new coordinate, and add the clone to the Pushpins collection. This will generate a new pushpin on the correct geo location on the map. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 13 Add Pushpin Clone) private void CreateNewPushpin(object selecteditem, Point point) Page 45

46 GeoCoordinate location; Map.TryViewportPointToLocation(point, out location); var pushpinprototype = selecteditem as PushpinModel; var pushpin = pushpinprototype.clone(location); Pushpins.Add(pushpin); 14. To change the pushpin colors, add the following brushes to the DefaultStyle.xaml located in the Resources\Styles project folder. <!-- # Brushes --> <SolidColorBrush x:key="pushpinbicyclebrush" Color="#FF593D00" /> <SolidColorBrush x:key="pushpincarbrush" Color="#FFEC098D" /> <SolidColorBrush x:key="pushpindrinkbrush" Color="#FFD21242" /> <SolidColorBrush x:key="pushpinfuelbrush" Color="#FFF47836" /> <SolidColorBrush x:key="pushpinhousebrush" Color="#FF00AFDB" /> <SolidColorBrush x:key="pushpinlocationbrush" Color="#FF3784DF" /> <SolidColorBrush x:key="pushpinrestaurantbrush" Color="#FF7D4199" /> <SolidColorBrush x:key="pushpinshopbrush" Color="#FF00B25A" /> 15. Add a new project folder called Converters, and within it create a new value converter class that converts the pushpin TypeName to the exact brush, and add it as a resource to the DefaultStyles.xaml resource dictionary. (Code Snippet Using Bing Maps Ex 2 Task 2 Step 15 PushpinTypeBrushConverter Class) public class PushpinTypeBrushConverter : IValueConverter Page 46

47 public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) var brushkey = string.format("0brush", value); var brush = Application.Current.Resources[brushKey]?? DefaultBrush; return brush; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotSupportedException(); static PushpinTypeBrushConverter() DefaultBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x37, 0x84, 0xDF)); public static Brush DefaultBrush; <ResourceDictionary... xmlns:converters="clr-namespace:usingbingmaps.converters"> <converters:pushpintypebrushconverter x:key="pushpintypebrushconverter" /> </ResourceDictionary> 16. In the MainPage.xaml, search for the Map control. In the pushpin data template, use the converter instance you created to bind the Pushpin.Background property to the PushpinModel.TypeName property. <my:mapitemscontrol ItemsSource="Binding Pushpins"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin Style="StaticResource PushpinStyle" Location="Binding Location" Page 47

48 Background="Binding TypeName, Converter=StaticResource PushpinTypeBrushConverter"> <Image Source="Binding Icon" /> </my:pushpin> </DataTemplate> </my:mapitemscontrol.itemtemplate> </my:mapitemscontrol> 17. To center the map on a pushpin while touching it, register the Pushpin.MouseLeftButtonUp event. Since the Pushpin is defined by a DataTemplate located directly inside MainPage.xaml, you can simply register the event handler over there. Otherwise you can use an Attached Behavior to activate a command. In the pushpin DataTemplate, register to the Pushpin.MouseLeftButtonUp event and handle it by setting the MainPage.Center property with the pushpin s Location property. You can extract the pushpin object from the event handler sender argument. <my:pushpin Style="StaticResource PushpinStyle" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp" Location="Binding Location" Background="Binding TypeName, Converter=StaticResource PushpinTypeBrushConverter"> <Image Source="Binding Icon" /> </my:pushpin> (Code Snippet Using Bing Maps Ex 2 Task 2 Step 17 Pushpin_MouseLeftButtonUp Event Handler) private void Pushpin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) var pushpin = sender as Pushpin; Center = pushpin.location; Page 48

49 18. To test the results, press F5, go to the default location, click and hold a position on the map then select a pushpin from the list. The pushpin you ve selected should be added to the map. Repeat this behavior for adding more pushpins. Click on any pushpin to center the map on it. Figure 27 Pushpin selection This concludes the exercise. Note: The complete solution for this exercise is provided at the following location: Source\Ex2-HandlingPushpins\End. Page 49

50 Exercise 3: Calculating a Route In this exercise we will: Create a map route layer Use Bing services to calculate to and from routes Display calculated route itineraries We will use the Microsoft Visual Studio 2010 Express for Windows Phone development environment, and will deploy to the Windows Phone Emulator for debugging. The solution we will be working with is based upon the previous exercise. Task 1 Adding a Route to the Map In this task you ll work with Bing Maps SOAP services to calculate a route from point A to point B, and then you ll create a route layer for rendering the calculated route. As part of the route rendering, you ll also render route itineraries provided by the Bing Maps services. In this task you ll use the following services: Geocode Service to match addresses, places, and geographic entities to latitude and longitude coordinates on the map, as well as return location information for a specified latitude and longitude coordinate Route Service to generate routes and driving directions based on locations or waypoints, for example, directions that include traffic warnings and route hints between multiple locations, and directions from all major roads to a destination (1-click directions, also referred to as a "party map") Search Service to parse a search query that contains a location or keyword (or both) and return search result 1. Open the starter solution located in the Source\Ex3-RouteCalculation\Begin folder. Note: You should set the Bing Maps application Id in the App class with your private key created in the previous exercise. Page 50

51 2. To add a reference to the Bing Maps Geocode service, right click on the project references, and select Add Service Reference. Figure 28 Add Service Reference 3. Paste the following service address into the opened dialog, and click Go: Page 51

52 4. In the Namespace field, make sure that you enter Bing.Geocode and then click OK. Figure 29 Bing Service Note: If you have problems generating the data from the service, please make sure that you are currently connected to the Internet. Try to paste the service address into the web browser;, you should get a service test page. If you have a connection, try to run Visual Studio 2010 again as Administrator (right click on Visual Studio 2010 icon on start menu, select Run as administrator ), then try again. 5. To add reference to the Bing Maps Route service, right-click the project references, and select Add Service Reference 6. Paste the following service address into the opened dialog, and click Go: 7. In the Namespace field, make sure that you enter Bing.Route and then click OK. 8. To add a reference to the Bing Maps Search service, right-click the project references, and select Add Service Reference Page 52

53 9. Paste the following service address into the opened dialog, and click Go: In the Namespace field, make sure that you enter Bing.Search and then click OK. 11. Open the ServiceReferences.ClientConfig configuration file that was automatically created as a project item and delete all CustomBinding related entries. In this lab we will use only the basic http bindings. You should have a file that looks like this: <configuration> <system.servicemodel> <bindings> <basichttpbinding> <binding name="basichttpbinding_igeocodeservice" maxbuffersize=" " maxreceivedmessagesize=" "> <security mode="none" /> </binding> <binding name="basichttpbinding_irouteservice" maxbuffersize=" " maxreceivedmessagesize=" "> <security mode="none" /> </binding> <binding name="basichttpbinding_isearchservice" maxbuffersize=" " maxreceivedmessagesize=" "> <security mode="none" /> </binding> </basichttpbinding> </bindings> <client> <endpoint address=" deservice.svc" binding="basichttpbinding" bindingconfiguration="basichttpbinding_igeocodeservice" contract="bing.geocode.igeocodeservice" name="basichttpbinding_igeocodeservice" /> <endpoint address=" rvice.svc" binding="basichttpbinding" bindingconfiguration="basichttpbinding_irouteservice" contract="bing.route.irouteservice" name="basichttpbinding_irouteservice" /> <endpoint address=" service.svc" Page 53

54 binding="basichttpbinding" bindingconfiguration="basichttpbinding_isearchservice" contract="bing.search.isearchservice" name="basichttpbinding_isearchservice" /> </client> </system.servicemodel> </configuration> Note: You ve now added three Bing Maps services. Next you ll add a helper class that uses these services to wrap part of the asynchronous calls for calculating a route. 12. Add the following files to the Helpers project folder: RouteCalculator.cs, RoutingState.cs, RouteCalculationError.cs, located in Source/Assets/Code. These files will help you calculate a route using the Bing Maps Services you ve added. The RouteCalculator class exposes one public method called CalculateAsync and one public event called Error. To calculate a route all you have to do is to initialize a new instance of the RouteCalculator type with the following parameter: Map credentials, To string, From string, UI dispatcher, and a delegate that will be called on the UI thread when calculation is done. If an error occurs, the Error event is raised on the UI thread. This is why you must pass the UI dispatcher. Figure 30 Route Helpers 13. Add a model public class called RouteModel to the Models project folder, for representing the route data. Page 54

55 14. In the RouteModel class add a new collection of type Microsoft.Phone.Controls.Maps.LocationCollection to hold the route coordinates, and expose this as a public property called Locations. 15. Create a constructor with one collection parameter of type Microsoft.Phone.Controls.Maps.Platform.Location. Use it to initialize the internal collection. Location has an implicit cast to the GeoCoordinate type. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 15 RouteModel Constructor) public class RouteModel private readonly LocationCollection _locations; public ICollection<GeoCoordinate> Locations get return _locations; public RouteModel(ICollection<Location> locations) _locations = new LocationCollection(); foreach (Location location in locations) _locations.add(location); 16. In the MainPage.xaml.cs, add a new ObservableCollection<RouteModel> and expose it with a public property called Routes. This collection holds the calculated route and will be bound with the route layer. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 16 Routes Property) private readonly ObservableCollection<RouteModel> _routes = new ObservableCollection<RouteModel>(); public ObservableCollection<RouteModel> Routes get return _routes; Page 55

56 17. Add two public string properties: To and From. You ll use these properties for the route calculation. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 17 To From Properties) public string To get; set; public string From get; set; 18. Find the CalculateRoute method and calculate a route using the route calculator helper class: Create a try/catch block and use MessageBox to display an error message in case an exception is caught. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 18 PushpinTypeBrushConverter Class) private void CalculateRoute() try // TODO : Calculate a route. catch (Exception ex) MessageBox.Show(ex.Message); 19. To calculate a route asynchronously, create an instance of RouteCalculator inside the try block. So far you should have all the required parameters as properties of the MainPage class, except for the last one which will be an empty lambda expression with a single result parameter. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 19 routecalculator) try var routecalculator = new RouteCalculator( CredentialsProvider, To, From, Dispatcher, result => Page 56

57 ); catch (Exception ex) MessageBox.Show(ex.Message); 20. Register the RouteCalculator.Error event by displaying an error message to the user and then call the RouteCalculator.CalculateAsync method to start the route calculation. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 20 Calculate) try var routecalculator = new RouteCalculator( CredentialsProvider, To, From, Dispatcher, result => ); // Display an error message in case of fault. routecalculator.error += r => MessageBox.Show(r.Reason); // Start the route calculation asynchronously. routecalculator.calculateasync(); catch (Exception ex) MessageBox.Show(ex.Message); 21. When the route calculation is finished, the lambda expression should be invoked. Inside the lambda expression, clear the Route collection. For the simplicity, you ll have only one route at a time. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 21 Clear Routes) result => Page 57

58 ; Routes.Clear(); 22. Below, create a new RouteModel instance based on route calculator parameter (result.result.routepath.points), and add the new route to the route collection. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 22 routemodel) var routemodel = new RouteModel(result.Result.RoutePath.Points); Routes.Add(routeModel); 23. Then, center the map on the new route, by calling Map.SetView, and passing it a LocationRect instance which is can be calculated using the LocationRect.CreateLocationRect static helper method. (Code Snippet Using Bing Maps Ex 3 Task 1 Step 23 viewrect) var viewrect = LocationRect.CreateLocationRect(routeModel.Locations); Map.SetView(viewRect); 24. To pick the route s to/from text, open the MainPage.xaml with the editor, find the RouteView border and add a new child composed of a Grid with two TextBlocks, one for From and the other for To. <Border x:name="routeview" Height="160" Margin="0" Padding="8" RenderTransformOrigin="0.5,0.5" Width="480" Background="StaticResource ControlBackgroundBrush"> <Border.RenderTransform> <CompositeTransform TranslateY="-160"/> </Border.RenderTransform> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="50" /> <ColumnDefinition Width="0.8*" /> <ColumnDefinition Width="0.2*"/> Page 58

59 </Grid.ColumnDefinitions> <TextBlock Text="From" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" /> <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" /> <TextBlock Text="To" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" /> <TextBox Grid.Row="1" Grid.Column="1" /> </Grid> </Border> 25. Bind each of the TextBlocks as two-way binding with the relevant To/From properties. <TextBox Text="Binding From, Mode=TwoWay"... /> <TextBox Text="Binding To, Mode=TwoWay"... /> 26. Add a Go button to the Grid, set its style with the ButtonGoStyle style and register its Click event with the ButtonGo_Click event handler. Both the style and the event handler are provided with the starter project. <Button Content="Go" Grid.Column="2" Grid.Row="1" Click="ButtonGo_Click" Style="StaticResource ButtonGoStyle" /> 27. To create a route layer, add another MapItemsControl to the map control just before the pushpins layer, and bind it to the Routes property. <my:mapitemscontrol ItemsSource="Binding Routes" /> 28. To draw the route as a single line on the map, set the MapItemsControl.ItemTemplate with a data templatethat contains a single MapPolyline instance. <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:mappolyline Stroke="#FF2C76B7" Opacity="0.85" StrokeThickness="6" /> Page 59

60 </DataTemplate> </my:mapitemscontrol.itemtemplate> 29. Bind the MapPolyline instance with the RouteModel.Locations property. <my:mappolyline Stroke="#FF2C76B7" Opacity="0.85" StrokeThickness="6" Locations="Binding Locations" /> 30. To test the application: Press F5 and then click on route icon on the application bar (the upward-facing arrow). The route view should slide down from the top. Write a valid address in the From and To fields. For example: Microsoft Redmond Building 1, WA, Microsoft Redmond Building 9, WA. Click the search icon. This should calculate the route and you should see it on the map. If an error occurs, you should see an error message. Page 60

61 Figure 31 Calculating a route Task 2 Displaying Route Itineraries The Bing route service supplies additional data with the route data, namely, the route itineraries data. By using the itineraries data you can display the exact directions of how to walk or drive from point A to point B on the route. In this task you ll create a directions list based on these itineraries. Page 61

62 1. In the MainPage.xaml.cs, add a new collection of type ItineraryItem, and expose it as public property called Itineraries. This type was auto generated as part of the Bing Route service data contracts. You ll use this class to encapsulate the itineraries collection provided with the route. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 1 ItineraryItem Property) private readonly ObservableCollection<ItineraryItem> _itineraries = new ObservableCollection<ItineraryItem>(); public ObservableCollection<ItineraryItem> Itineraries get return _itineraries; 2. Find the CalculateRoute method and clear both the Routes collection and the Itineraries collection. Since you re displaying only one route at a time you ll provide the itineraries of that active route. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 2 Clear Itineraries) result => Routes.Clear(); Itineraries.Clear(); After adding the new route to the collection of routes, add all the itineraries provided by result.result.legs[0] right. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 3 Add Itineraries) var routemodel = new RouteModel(result.Result.RoutePath.Points); Routes.Add(routeModel); foreach (var itineraryitem in result.result.legs[0].itinerary) Itineraries.Add(itineraryItem); Page 62

63 4. In the MainPage.xaml, use the MapItemsControl to add a new layer for the itineraries, right below the routed layer, and bind it with the Itineraries collection. <my:mapitemscontrol ItemsSource="Binding Itineraries"> </my:mapitemscontrol> 5. To display each Itinerary as a custom pushpin, set the MapItemsControl.ItemTemplate with a new data template that contains a single pushpin. <my:mapitemscontrol ItemsSource="Binding Itineraries"> <my:mapitemscontrol.itemtemplate> <DataTemplate> <my:pushpin /> </DataTemplate> </my:mapitemscontrol.itemtemplate> </my:mapitemscontrol> 6. Bind the pushpin with the ItineraryItem.Location property. <my:pushpin Location="Binding Location" /> 7. To convert the Location property to a GeoCoordinate, create a value converter. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 7 LocationGeoCoordinateConverter) public class LocationGeoCoordinateConverter : IValueConverter public object Convert(object value, Type targettype, object parameter, CultureInfo culture) var location = (Location)value; return (GeoCoordinate)location; public object ConvertBack(object value, Type targettype, object parameter, CultureInfo culture) Page 63

64 throw new NotSupportedException(); 8. Create an instance of the value converter inside the DefaultStyles.xaml resource dictionary located in the Resources\Styles folder. <ResourceDictionary... xmlns:converters="clr-namespace:usingbingmaps.converters" mc:ignorable="d"> <converters:locationgeocoordinateconverter x:key="locationgeocoordinateconverter" />... </ResourceDictionary> 9. Use the converter inside the binding extension. <my:pushpin Location="Binding Location, Converter=StaticResource LocationGeoCoordinateConverter" /> 10. Create a style for displaying the itinerary pushpin as a rounded shape and place it inside the DefaultStyle.xaml resource dictionary located in the Resources\Styles folder. <Style x:key="mappoint" TargetType="Ellipse"> <Setter Property="Width" Value="18"/> <Setter Property="Height" Value="18"/> <Setter Property="Fill" Value="#FF003664"/> <Setter Property="Stroke" Value="AliceBlue"/> </Style> <Style x:key="itinerarypushpinstyle" TargetType="m:Pushpin"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="m:Pushpin"> <Grid Height="20" Width="20"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:name="visualstategroup"> Page 64

65 GeneratedDuration="0:0:0.1"> <VisualStateGroup.Transitions> <VisualTransition <VisualTransition.GeneratedEasingFunction> EasingMode="EaseIn"/> <PowerEase </VisualTransition.GeneratedEasingFunction> </VisualTransition> <VisualTransition GeneratedDuration="0:0:0.1" To="Selected"> <VisualTransition.GeneratedEasingFunction> EasingMode="EaseIn"/> <PowerEase </VisualTransition.GeneratedEasingFunction> </VisualTransition> </VisualStateGroup.Transitions> <VisualState x:name="unselected"/> <VisualState x:name="selected"> <Storyboard> <ColorAnimation Duration="0" To="White" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="ellipse" d:isoptimized="true"/> <DoubleAnimation Duration="0" To="1.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransfo rm.scalex)" Storyboard.TargetName="ellipse" d:isoptimized="true"/> <DoubleAnimation Duration="0" To="1.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransfo rm.scaley)" Storyboard.TargetName="ellipse" d:isoptimized="true"/> <ColorAnimation Duration="0" To="#FFF08609" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="ellipse_Center" d:isoptimized="true"/> <DoubleAnimation Duration="0" To="1.5" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransfo rm.scalex)" Storyboard.TargetName="ellipse_Center" d:isoptimized="true"/> <DoubleAnimation Duration="0" To="1.5" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransfo Page 65

66 rm.scaley)" Storyboard.TargetName="ellipse_Center" d:isoptimized="true"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Ellipse x:name="ellipse" Style="StaticResource MapPoint" Width="20" Height="20" RenderTransformOrigin="0.5,0.5" Fill="White" Stroke="#FF2C76B7" StrokeThickness="3" > <Ellipse.RenderTransform> <CompositeTransform/> </Ellipse.RenderTransform> </Ellipse> <Ellipse x:name="ellipse_center" Style="StaticResource MapPoint" Width="8" Height="8" RenderTransformOrigin="0.5,0.5" Fill="Black" Stroke="x:Null" StrokeThickness="2" > <Ellipse.RenderTransform> <CompositeTransform/> </Ellipse.RenderTransform> </Ellipse> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 11. Change the pushpin s style to the new style you ve just created. <my:pushpin Location="Binding Location, Converter=StaticResource LocationGeoCoordinateConverter" Style="StaticResource ItineraryPushpinStyle" /> 12. To test the results, press F5 and calculate a valid route. Page 66

67 Figure 32 Route with Itineraries 13. To display a list of all itineraries related to the active route, open the MainPage.xaml and search for a border named DirectionsView. This is a place holder for the itineraries view. As a child of this border, add a ListBox control and bind it to the Itineraries collection. <ListBox ItemsSource="Binding Itineraries" Margin="0,10" /> 14. To display the different parts of the itinerary, such as the directions text and distance, create an item template composed of a horizontal StackPanel, which contains three TextBlock one for the direction instructions, one for the distance, and one for the distance unit. Page 67

68 <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="5,2.5"> <TextBlock FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF666666" /> <TextBlock Margin="4,0,0,0" FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF1BA1E2" /> <TextBlock Text="mi" FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF1BA1E2" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> 15. Bind the first text block to the Itinerary.Text property. <TextBlock FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF666666" Text="Binding Text" /> Note: Itinerary.Text represents collection of XML elements. Each element represents a different part of the directions story, such as distance, location name, action (turn left, right, etc.). To reduce the lab s complexity, you ll create a value converter which converts all elements from the text property into a single line text sentence. 16. Add a new value converter called ItineraryTextConverter to the Converters project folder. Note: To implement a value converter class, inherit the class from the IValueConverter interface and implement its methods by right clicking on the interface name. By doing this you will implement the Convert and ConvertBack stub methods. Page 68

69 17. In the Convert method, create a StringBuilder used for building the single line text sentence. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 17 textbuilder) var textbuilder = new StringBuilder(); Note: Since Itinerary.Text doesn t represent a well formatted XML, and instead provides a collection of elements with no root element, and because the VirtualEarth prefix is used but is not defined, we're adding a fictitious root element that also maps the VirtualEarth prefix to a fictitious namespace. 18. Create a string variable with the following content: (Code Snippet Using Bing Maps Ex 3 Task 2 Step 18 validxmltext) string validxmltext = string.format("<directives xmlns:virtualearth=\" value); Note: Since we are dealing with XML and Linq, make sure you add reference to the following assemblies: System.Xml and System.Xml.Linq. Also make sure that you have a using statement for System.Linq. 19. Use XDocument to parse the XML, extract all element values, and append each to the StringBuilder. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 19 Parse XML) XDocument.Parse(validXmlText).Elements().Select(e => e.value).tolist().foreach(v => textbuilder.append(v)); 20. Return the StringBuilder results. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 20 Return Results) return textbuilder.tostring(); Page 69

70 21. In the DefaultStyles.xaml, add an instance of the converter you ve created. <ResourceDictionary... xmlns:converters="clr-namespace:usingbingmaps.converters"...> <converters:itinerarytextconverter x:key="itinerarytextconverter" />... </ResourceDictionary> 22. Go back to the Itinerary item template and use the converter with the binding markup. <TextBlock FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF666666" Text="Binding Text, Converter=StaticResource ItineraryTextConverter" /> 23. Bind the second TextBlock with the Itinerary.Summary.Distance property. <TextBlock Margin="4,0,0,0" FontFamily="Segoe WP" FontWeight="Light" FontSize="20" Foreground="#FF1BA1E2" Text="Binding Summary.Distance" /> 24. To display the itinerary view right after a route was found, in the MainPage.xaml.cs search the HasDirections property and return true if the Itinerary collection is not empty. (Code Snippet Using Bing Maps Ex 3 Task 2 Step 24 HasDirectories Property) public bool HasDirections get return Itineraries.Count > 0; Page 70

71 25. In the CalculateRoute method, call the ShowDirectionsView inside the lambda body, right after setting the map view. // Set the map to center on the new route. var viewrect = LocationRect.CreateLocationRect(routeModel.Locations); Map.SetView(viewRect); ShowDirectionsView(); 26. To simplify testing, search for the InitializeDefaults, and set the following defaults: (Code Snippet Using Bing Maps Ex 3 Task 2 Step 26 Set Defaults) private void InitializeDefaults() Zoom = DefaultZoomLevel; Center = DefaultLocation; From = "Microsoft Redmond Building 1, WA"; To = "Microsoft Redmond Building 9, WA"; Page 71

72 27. To test the final application, press F5 and search for a valid route. The directions view should pop up automatically. Figure 33 Bing Maps Final This concludes the exercise and the lab. Note: The complete solution for this exercise is provided at the following location: Source\Ex3-RouteCalculation\End. Page 72

Introduction to Data Templates and Value Converters in Silverlight

Introduction to Data Templates and Value Converters in Silverlight Introduction to Data Templates and Value Converters in Silverlight An overview of Data Templates and Value Converters by JeremyBytes.com Overview Business applications are all about data, and laying out

More information

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver Windows 10 UWP Hands on Lab Lab 2: Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver 10240. 1. Select the Models folder and bring up the popup menu and

More information

Week 8: Data Binding Exercise (Bookstore)

Week 8: Data Binding Exercise (Bookstore) BCIS 4650 Week 8: Data Binding Exercise (Bookstore) Page 1 of 6 Page 2 of 6 XAML CODE FOR MainPage.xaml

More information

Portable Class Libraries ---

Portable Class Libraries --- Portable Class Libraries --- Overview In this lab, you ll learn about Portable Class Libraries (PCLs). PCLs enable you to create managed assemblies that work on more than one.net Framework platform. Within

More information

Hands-On Lab. Hello Windows Phone

Hands-On Lab. Hello Windows Phone Hands-On Lab Hello Windows Phone Lab version: 1.1.0 Last updated: 12/8/2010 CONTENTS OVERVIEW... 3 EXERCISE 1: CREATING WINDOWS PHONE APPLICATIONS WITH MICROSOFT VISUAL STUDIO 2010 EXPRESS FOR WINDOWS

More information

Hands-On Lab. Using Pivot and Panorama Controls

Hands-On Lab. Using Pivot and Panorama Controls Hands-On Lab Using Pivot and Panorama Controls Lab version: 1.0.0 Last updated: 12/8/2010 CONTENTS Overview... 3 Exercise 1: Introduction to Navigation in Windows Phone... 7 Task 1 Creating a Windows Phone

More information

Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year!

Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year! IT TEST BOOK QUESTION & ANSWER Ittestbook provides update free of charge in one year! Accurate study guides, High passing rate! Exam : 070-506 Title : TS: Microsoft Silverlight 4, Development Version :

More information

Authoring Guide v2.1 PATRIK SUNDQVIST

Authoring Guide v2.1 PATRIK SUNDQVIST 2012 Authoring Guide v2.1 PATRIK SUNDQVIST Purpose The purpose of this document is to provide assistance when customizing WebFront for Service Manager 2012. 1 TABLE OF CONTENTS 2 Introduction... 2 3 Limitations...

More information

Developing Native Windows Phone 7 Applications for SharePoint

Developing Native Windows Phone 7 Applications for SharePoint Developing Native Windows Phone 7 Applications for SharePoint Steve Pietrek Cardinal Solutions About Cardinal OUR FOCUS: Enterprise Rich Internet Applications Mobile Solutions Portals & Collaboration Business

More information

Authoring Guide Gridpro AB Rev: Published: March 2014

Authoring Guide Gridpro AB Rev: Published: March 2014 Authoring Guide Gridpro AB Rev: 2.5.5197 Published: March 2014 Contents Purpose... 3 Introduction... 3 Limitations... 3 Prerequisites... 3 Customizing Forms... 4 Launching the Customization Editor... 4

More information

Weather forecast ( part 2 )

Weather forecast ( part 2 ) Weather forecast ( part 2 ) In the first part of this tutorial, I have consumed two webservices and tested them in a Silverlight project. In the second part, I will create a user interface and use some

More information

windows-10-universal #windows- 10-universal

windows-10-universal #windows- 10-universal windows-10-universal #windows- 10-universal Table of Contents About 1 Chapter 1: Getting started with windows-10-universal 2 Remarks 2 Examples 2 Installation or Setup 2 Creating a new project (C# / XAML)

More information

WebFront for Service Manager

WebFront for Service Manager WebFront for Service Manager Authoring Guide Gridpro AB Rev: 2.10.6513 (System Center 2012) & 3.0.6513 (System Center 2016) Published: November 2017 Contents Purpose... 3 Introduction... 3 Limitations...

More information

Microsoft Corporation

Microsoft Corporation Microsoft Corporation http://www.jeff.wilcox.name/ 2 3 Display 480x800 QVGA Other resolutions in the future Capacitive touch 4+ contact points Sensors A-GPS, Accelerometer, Compass, Light Camera 5+ megapixels

More information

RadGanttView For Silverlight and WPF

RadGanttView For Silverlight and WPF RadGanttView For Silverlight and WPF This tutorial will introduce RadGanttView, part of the Telerik suite of XAML controls. Setting Up The Project To begin, open Visual Studio and click on the Telerik

More information

RadPDFViewer For Silverlight and WPF

RadPDFViewer For Silverlight and WPF RadPDFViewer For Silverlight and WPF This tutorial will introduce the RadPDFViewer control, part of the Telerik suite of XAML controls Setting Up The Project To begin, open Visual Studio and click on the

More information

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule Hands-On Lab Building Applications in Silverlight 4 Module 6: 1 P a g e Contents Introduction... 3 Exercise 1: on One Page... 4 Create the Printing ViewModel and View... 4 Hook up the Print Button... 7

More information

Week 7: NavigationView Control Exercise

Week 7: NavigationView Control Exercise BCIS 4650 Week 7: NavigationView Control Exercise BUILD THE UI FIRST (ALWAYS). ================================================================================================ 1. Start with a New Project

More information

Name of Experiment: Country Database

Name of Experiment: Country Database Name of Experiment: Country Database Exp No: DB2 Background: Student should have basic knowledge of C#. Summary: Database Management is one of the key factors in any Mobile application development framework.

More information

Lesson 9: Exercise: Tip Calculator

Lesson 9: Exercise: Tip Calculator Lesson 9: Exercise: Tip Calculator In this lesson we ll build our first complete app, a Tip Calculator. It will help solve one of the fundamental problems that I have whenever I'm out to a restaurant,

More information

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Author...

More information

Bringing Together One ASP.NET

Bringing Together One ASP.NET Bringing Together One ASP.NET Overview ASP.NET is a framework for building Web sites, apps and services using specialized technologies such as MVC, Web API and others. With the expansion ASP.NET has seen

More information

This walkthrough assumes you have completed the Getting Started walkthrough and the first lift and shift walkthrough.

This walkthrough assumes you have completed the Getting Started walkthrough and the first lift and shift walkthrough. Azure Developer Immersion In this walkthrough, you are going to put the web API presented by the rgroup app into an Azure API App. Doing this will enable the use of an authentication model which can support

More information

Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox.

Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox. Name of Experiment: Display the Unicode for the key-board characters. Exp No:WP4 Background: Student should have a basic knowledge of C#. Summary: After going through this experiment, the student is aware

More information

Windows Presentation Foundation. Jim Fawcett CSE687 Object Oriented Design Spring 2018

Windows Presentation Foundation. Jim Fawcett CSE687 Object Oriented Design Spring 2018 Windows Presentation Foundation Jim Fawcett CSE687 Object Oriented Design Spring 2018 References Pro C# 5 and the.net 4.5 Platform, Andrew Troelsen, Apress, 2012 Programming WPF, 2nd edition, Sells & Griffiths,

More information

Lab 7: Silverlight API

Lab 7: Silverlight API Lab 7: Silverlight API Due Date: 02/07/2014 Overview Microsoft Silverlight is a development platform for creating engaging, interactive user experiences for Web, desktop, and mobile applications when online

More information

ComponentOne. HyperPanel for WPF

ComponentOne. HyperPanel for WPF ComponentOne HyperPanel for WPF Copyright 1987-2012 GrapeCity, Inc. All rights reserved. ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Internet:

More information

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom CS3240 Lab SEM 1 2009/2010 Page 1 Overview In this lab, you will get familiarized with interactive media elements such

More information

Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010

Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010 Hands-On Lab Sensors -.NET Lab version: 1.0.0 Last updated: 12/3/2010 CONTENTS OVERVIEW... 3 EXERCISE 1: INTEGRATING THE SENSOR API INTO A WPF APPLICATION... 5 Task 1 Prepare a WPF Project for Sensor Integration...

More information

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1 Hands-On Lab Launchers and Choosers Lab version: 1.0.0 Last updated: 12/8/2010 Page 1 CONTENTS Overview... 3 Exercise 1: Introduction to the Windows Phone Launchers... 8 Task 1 Adding and Navigating to

More information

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145 Navigation in Silverlight -3 1. Introduction: In previous article we learn to navigate to another Silverlight page without using navigation framework, which is new feature in Silverlight 3. Read it Here:

More information

Week 6: First XAML Control Exercise

Week 6: First XAML Control Exercise BCIS 4650 Week 6: First XAML Control Exercise The controls you will use are: Blank App (Universal Windows), which contains a Grid control by default StackPanel (acts as a container for CheckBoxes and RadioButtons)

More information

E, F. Data contracts, 50 Data visualization. See Power Map, Excel Debugging, 63

E, F. Data contracts, 50 Data visualization. See Power Map, Excel Debugging, 63 Index A, B Basic binding, 50 Binary Large Objects (Blobs), 14 Bindings, 49 basic binding, 50 definition, 49 IPC binding, 50 MSMQ binding, 50 web service binding, 50 Bing Map(s), 79, 101 animated transitions,

More information

CS3240 Human-Computer Interaction Lab Sheet Lab Session 3 Designer & Developer Collaboration

CS3240 Human-Computer Interaction Lab Sheet Lab Session 3 Designer & Developer Collaboration CS3240 Human-Computer Interaction Lab Sheet Lab Session 3 Designer & Developer Collaboration Page 1 Overview In this lab, users will get themselves familarise with fact that Expression Blend uses the identical

More information

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp COMP 585 Noteset #12 Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp. 46-48. WPF: More Code vs. Markup The apparently recommended way to use

More information

The finished application DEMO ios-specific C# Android-specific C# Windows-specific C# Objective-C in XCode Java in Android Studio C# Shared Logic C# in Visual Studio ios codebase Android codebase Windows

More information

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins Wolfgang Kaiser Session Overview MVVM Model View ViewModel - View and View Model Implementation in Pro - Dockpane Example - MVVM concepts - Multi

More information

ComponentOne. Extended Library for UWP

ComponentOne. Extended Library for UWP ComponentOne Extended Library for UWP ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Website: http://www.componentone.com Sales: sales@componentone.com

More information

Beginning Silverlight 5 in C #

Beginning Silverlight 5 in C # Table of Contents: Chapter 1. Welcome to Silverlight 5 1.1 The Evolution of the User interface 1.2 Rich Internet Application Solutions 1.3 What is Silverlight? 1.4 Benefits of Silverlight 1.4.1 Cross-Platform/Cross-Browser

More information

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins Wolfgang Kaiser Framework Elements - Recap Any Framework Element is an extensibility point - Controls (Button, Tool, and variants) - Hosted on

More information

Hands-On Lab. Worker Role Communication. Lab version: Last updated: 11/16/2010. Page 1

Hands-On Lab. Worker Role Communication. Lab version: Last updated: 11/16/2010. Page 1 Hands-On Lab Worker Role Communication Lab version: 2.0.0 Last updated: 11/16/2010 Page 1 CONTENTS OVERVIEW... 3 EXERCISE 1: USING WORKER ROLE EXTERNAL ENDPOINTS... 8 Task 1 Exploring the AzureTalk Solution...

More information

CPSC Tutorial 5

CPSC Tutorial 5 CPSC 481 - Tutorial 5 Assignment #2 and WPF (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, Sowmya Somanath, and Kevin Ta) Introduction Contact Info li26@ucalgary.ca

More information

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod ArcGIS Pro SDK for.net UI Design for Accessibility Charles Macleod Overview Styling - Light, Dark, High Contrast Accessibility Custom Styling* Add-in Styling Since1.4: Light and Dark Theme and High Contrast

More information

Master Code on Innovation and Inclusion

Master Code on Innovation and Inclusion Microsoft x HKEdCity: Master Code on Innovation and Inclusion Train-the-Trainers Workshop Writing Applications in C# with Visual Studio Content I. Getting the Tools Ready... 3 II. Getting Started with

More information

Windows Presentation Foundation Programming Using C#

Windows Presentation Foundation Programming Using C# Windows Presentation Foundation Programming Using C# Duration: 35 hours Price: $750 Delivery Option: Attend training via an on-demand, self-paced platform paired with personal instructor facilitation.

More information

CPSC Tutorial 5 WPF Applications

CPSC Tutorial 5 WPF Applications CPSC 481 - Tutorial 5 WPF Applications (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, and Sowmya Somanath) Today Horizontal Prototype WPF Applications Controls

More information

PART I: INTRODUCTION TO WINDOWS 8 APPLICATION DEVELOPMENT CHAPTER 1: A BRIEF HISTORY OF WINDOWS APPLICATION DEVELOPMENT 3

PART I: INTRODUCTION TO WINDOWS 8 APPLICATION DEVELOPMENT CHAPTER 1: A BRIEF HISTORY OF WINDOWS APPLICATION DEVELOPMENT 3 INTRODUCTION xix PART I: INTRODUCTION TO WINDOWS 8 APPLICATION DEVELOPMENT CHAPTER 1: A BRIEF HISTORY OF WINDOWS APPLICATION DEVELOPMENT 3 The Life of Windows 3 From Windows 3.1 to 32-bit 4 Windows XP

More information

Lesson 10: Exercise: Tip Calculator as a Universal App

Lesson 10: Exercise: Tip Calculator as a Universal App Lesson 10: Exercise: Tip Calculator as a Universal App In this lesson we're going to take the work that we did in the previous lesson and translate it into a Universal App, which will allow us to distribute

More information

Lecture # 6 Engr. Ali Javed 11th March, 2014

Lecture # 6 Engr. Ali Javed 11th March, 2014 Lecture # 6 Engr. Ali Javed 11 th March, 2014 Instructor s Information Instructor: Engr. Ali Javed Assistant Professor Department of Software Engineering U.E.T Taxila Email: ali.javed@uettaxila.edu.pk

More information

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code.

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code. About the Tutorial Every good developer wants and tries to create the most sophisticated applications to delight their users. Most of the times, developers achieve this on the first release of the application.

More information

CHANNEL9 S WINDOWS PHONE 8.1 DEVELOPMENT FOR ABSOLUTE BEGINNERS

CHANNEL9 S WINDOWS PHONE 8.1 DEVELOPMENT FOR ABSOLUTE BEGINNERS CHANNEL9 S WINDOWS PHONE 8.1 DEVELOPMENT FOR ABSOLUTE BEGINNERS Full Text Version of the Video Series Published April, 2014 Bob Tabor http://www.learnvisualstudio.net Contents Introduction... 2 Lesson

More information

Exam sell. Higher Quality Better Service! Certified IT practice exam authority.

Exam sell. Higher Quality Better Service! Certified IT practice exam authority. Higher Quality Better Service! Exam sell Certified IT practice exam authority Accurate study guides, High passing rate! Exam Sell provides update free of charge in one year! http://www.examsell.com Exam

More information

UWP Working with Navigation

UWP Working with Navigation UWP-019 - Working with Navigation Up until now we've only created apps with a single Page, the MainPage.XAML, and while that's fine for simple apps. However, it s likely that you will need to add additional

More information

Yes, this is still a listbox!

Yes, this is still a listbox! Yes, this is still a listbox! Step 1: create a new project I use the beta 2 of Visual Studio 2008 ( codename Orcas ) and Expression Blend 2.0 September preview for this tutorial. You can download the beta2

More information

Google Earth Tutorial 1: The Basics of Map-making in Google Earth 6.2

Google Earth Tutorial 1: The Basics of Map-making in Google Earth 6.2 Google Earth Tutorial 1: The Basics of Map-making in Google Earth 6.2 University of Waterloo Map Library, 2012 Part 1: Placemarks 1. Locating a Geographical Area a. Open up Google Earth. b. In the Search

More information

Name of Experiment: Student Database

Name of Experiment: Student Database Name of Experiment: Student Database Exp No: DB1 Background: Student should have basic knowledge of C#. Summary: DBMS is a necessary requirement for any Mobile Application. We need to store and retrieve

More information

Developing Intelligent Apps

Developing Intelligent Apps Developing Intelligent Apps Lab 1 Creating a Simple Client Application By Gerry O'Brien Overview In this lab you will construct a simple client application that will call an Azure ML web service that you

More information

Advanced Programming C# Lecture 3. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 3. dr inż. Małgorzata Janik Advanced Programming C# Lecture 3 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 Windows Presentation Foundation Windows Presentation Foundation Allows for clear separation between

More information

Azure Developer Immersions API Management

Azure Developer Immersions API Management Azure Developer Immersions API Management Azure provides two sets of services for Web APIs: API Apps and API Management. You re already using the first of these. Although you created a Web App and not

More information

Migrating to Windows Phone

Migrating to Windows Phone BOOKS FOR PROFESSIONALS BY PROFESSIONALS Liberty Blankenburg RELATED Migrating to Windows Phone Upgrade your existing programming knowledge and begin developing for the Windows Phone with Migrating to

More information

CS3240 Human-Computer Interaction

CS3240 Human-Computer Interaction CS3240 Human-Computer Interaction Lab Session 3 Supplement Creating a Picture Viewer Silverlight Application Page 1 Introduction This supplementary document is provided as a reference that showcases an

More information

Building Next Generation GUIs using Microsoft Expression Interactive Designer

Building Next Generation GUIs using Microsoft Expression Interactive Designer Building Next Generation GUIs using Microsoft Expression Interactive Designer Adnan Farooq Hashmi MVP Windows SDK User Group Leader, Core.NET Speaker INETA Pakistan www.pkblogs.com/coredotnet Please note

More information

Your First Windows Form

Your First Windows Form Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

More information

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations Part I Integrated Development Environment Chapter 1: A Quick Tour Chapter 2: The Solution Explorer, Toolbox, and Properties Chapter 3: Options and Customizations Chapter 4: Workspace Control Chapter 5:

More information

Real-Time SignalR. Overview

Real-Time SignalR. Overview Real-Time SignalR Overview Real-time Web applications feature the ability to push server-side content to the connected clients as it happens, in real-time. For ASP.NET developers, ASP.NET SignalR is a

More information

LESSON B. The Toolbox Window

LESSON B. The Toolbox Window The Toolbox Window After studying Lesson B, you should be able to: Add a control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the

More information

STARCOUNTER. Technical Overview

STARCOUNTER. Technical Overview STARCOUNTER Technical Overview Summary 3 Introduction 4 Scope 5 Audience 5 Prerequisite Knowledge 5 Virtual Machine Database Management System 6 Weaver 7 Shared Memory 8 Atomicity 8 Consistency 9 Isolation

More information

WPF and MVVM Study Guides

WPF and MVVM Study Guides 1. Introduction to WPF WPF and MVVM Study Guides https://msdn.microsoft.com/en-us/library/mt149842.aspx 2. Walkthrough: My First WPF Desktop Application https://msdn.microsoft.com/en-us/library/ms752299(v=vs.110).aspx

More information

BCIS 4650 Visual Programming for Business Applications

BCIS 4650 Visual Programming for Business Applications BCIS 4650 Visual Programming for Business Applications XAML Controls (That You Will, or Could, Use in Your BCIS 4650 App i.e., a Subset) 1 What is a XAML Control / Element? Is a Toolbox class which, when

More information

ComponentOne. PdfViewer for WPF and Silverlight

ComponentOne. PdfViewer for WPF and Silverlight ComponentOne PdfViewer for WPF and Silverlight GrapeCity US GrapeCity 201 South Highland Avenue, Suite 301 Pittsburgh, PA 15206 Tel: 1.800.858.2739 412.681.4343 Fax: 412.681.4384 Website: https://www.grapecity.com/en/

More information

var xdoc = XDocument.Load(inStream);

var xdoc = XDocument.Load(inStream); Gradebook Sample App Summary: The goal of this project is to demonstrate how to share code across project types by using a Portable Class Library between a traditional Windows* Desktop application and

More information

Sparkline for WPF 1. ComponentOne. Sparkline for WPF

Sparkline for WPF 1. ComponentOne. Sparkline for WPF Sparkline for WPF 1 ComponentOne Sparkline for WPF Sparkline for WPF 2 ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Website: http://www.componentone.com

More information

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio Introduction XXV Part I: C# Fundamentals 1 Chapter 1: The.NET Framework 3 What s the.net Framework? 3 Common Language Runtime 3.NET Framework Class Library 4 Assemblies and the Microsoft Intermediate Language

More information

Kendo UI. Builder by Progress : Using Kendo UI Designer

Kendo UI. Builder by Progress : Using Kendo UI Designer Kendo UI Builder by Progress : Using Kendo UI Designer Copyright 2017 Telerik AD. All rights reserved. December 2017 Last updated with new content: Version 2.1 Updated: 2017/12/22 3 Copyright 4 Contents

More information

Using Dreamweaver. 4 Creating a Template. Logo. Page Heading. Home About Us Gallery Ordering Contact Us Links. Page content in this area

Using Dreamweaver. 4 Creating a Template. Logo. Page Heading. Home About Us Gallery Ordering Contact Us Links. Page content in this area 4 Creating a Template Now that the main page of our website is complete, we need to create the rest of the pages. Each of them will have a layout that follows the plan that is shown below. Logo Page Heading

More information

Creating a Template in WordPerfect

Creating a Template in WordPerfect 1. File a. New From Project Creating a Template in WordPerfect b. Go to Options 2. Create A Category 1 3. Name it Family History (or a title of your choice) 4. Find Family History in the Drop down list

More information

Reference Services Division Presents. Microsoft Word 2

Reference Services Division Presents. Microsoft Word 2 Reference Services Division Presents Microsoft Word 2 This handout covers the latest Microsoft Word 2010. This handout includes instructions for the tasks we will be covering in class. Basic Tasks Review

More information

Windows Phone 8 Game Development

Windows Phone 8 Game Development Windows Phone 8 Game Development Marcin Jamro Chapter No. 8 "Maps, Geolocation, and Augmented Reality" In this package, you will find: A Biography of the author of the book A preview chapter from the book,

More information

CHAPTER 1: INTRODUCING C# 3

CHAPTER 1: INTRODUCING C# 3 INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the.net Framework? 4 What s in the.net Framework? 4 Writing Applications Using the.net Framework 5 What Is C#? 8 Applications

More information

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version :

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version : Microsoft 70-511 Windows Apps Dev w/microsoft.net Framework 4 Download Full Version : https://killexams.com/pass4sure/exam-detail/70-511 Answer: A, C QUESTION: 215 You develop a Windows Presentation Foundation

More information

This document contains a general description of the MVVMStarter project, and specific guidelines for how to add a new domain class to the project.

This document contains a general description of the MVVMStarter project, and specific guidelines for how to add a new domain class to the project. MVVMStarter Guide This document contains a general description of the MVVMStarter project, and specific guidelines for how to add a new domain class to the project. Table of Content Introduction...2 Purpose...2

More information

Developing Rich Internet Applications Using Microsoft Silverlight 4

Developing Rich Internet Applications Using Microsoft Silverlight 4 Developing Rich Internet Applications Using Microsoft Silverlight 4 Course No. 10554 5 Days Instructor-led, Hands-on Introduction This course covers intermediate and advanced topics required to develop

More information

ArtOfTest Inc. Automation Design Canvas 2.0 Beta Quick-Start Guide

ArtOfTest Inc. Automation Design Canvas 2.0 Beta Quick-Start Guide Automation Design Canvas 2.0 Beta Quick-Start Guide Contents Creating and Running Your First Test... 3 Adding Quick Verification Steps... 10 Creating Advanced Test Verifications... 13 Creating a Data Driven

More information

ADF Mobile Code Corner

ADF Mobile Code Corner ADF Mobile Code Corner m03. Abstract: Dependent lists is a common functional requirement for web, desktop and also mobile applications. You can build dependent lists from dependent, nested, and from independent,

More information

Microsoft Exam TS: Windows Applications Development with Microsoft.NET Framework 4 Version: 58.5 [ Total Questions: 228 ]

Microsoft Exam TS: Windows Applications Development with Microsoft.NET Framework 4 Version: 58.5 [ Total Questions: 228 ] s@lm@n Microsoft Exam 70-511 TS: Windows Applications Development with Microsoft.NET Framework 4 Version: 58.5 [ Total Questions: 228 ] Topic 1, C# Question No : 1 - (Topic 1) You use Microsoft.NET Framework

More information

EXAM TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product.

EXAM TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product. Microsoft EXAM - 70-511 TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product http://www.examskey.com/70-511.html Examskey Microsoft 70-511 exam demo product is here for you to test

More information

Sample A2J Guided Interview & HotDocs Template Exercise

Sample A2J Guided Interview & HotDocs Template Exercise Sample A2J Guided Interview & HotDocs Template Exercise HotDocs Template We are going to create this template in HotDocs. You can find the Word document to start with here. Figure 1: Form to automate Converting

More information

This book was purchased by

This book was purchased by This book was purchased by arosner@rosnertech.com Table of Contents 1. Introduction and Tooling 2. Controls 3. Data Binding 4. Views 5. Local Data 6. Remote data and services 7. Charms and Contracts 8.

More information

User Interface Changes for SYSPRO

User Interface Changes for SYSPRO User Interface Changes for SYSPRO User Interface Changes for SYSPRO 7 3 Table of Contents Introduction... 4 User Interface Themes and Preferences... 4 Changes to the main menu in SYSPRO... 11 Conversion

More information

WRITING THE MANAGEMENT SYSTEM APPLICATION

WRITING THE MANAGEMENT SYSTEM APPLICATION Chapter 10 WRITING THE MANAGEMENT SYSTEM APPLICATION We are going to write an application which will read and evaluate the data coming from our Arduino card reader application. We are going to make this

More information

Installation and Configuration Manual

Installation and Configuration Manual Installation and Configuration Manual IMPORTANT YOU MUST READ AND AGREE TO THE TERMS AND CONDITIONS OF THE LICENSE BEFORE CONTINUING WITH THIS PROGRAM INSTALL. CIRRUS SOFT LTD End-User License Agreement

More information

Copyright 2018 MakeUseOf. All Rights Reserved.

Copyright 2018 MakeUseOf. All Rights Reserved. 15 Power User Tips for Tabs in Firefox 57 Quantum Written by Lori Kaufman Published March 2018. Read the original article here: https://www.makeuseof.com/tag/firefox-tabs-tips/ This ebook is the intellectual

More information

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING SAMPLE CHAPTER C# and XAML Pete Brown MANNING Windows Store App Development by Pete Brown Chapter 18 Copyright 2013 Manning Publications brief contents 1 Hello, Modern Windows 1 2 The Modern UI 19 3 The

More information

[MS10553]: Fundamentals of XAML and Microsoft Expression Blend

[MS10553]: Fundamentals of XAML and Microsoft Expression Blend [MS10553]: Fundamentals of XAML and Microsoft Expression Blend Length : 3 Days Audience(s) : Developers Level : 200 Technology : Microsoft Expression Blend Delivery Method : Instructor-led (classroom)

More information

InDesign Tools Overview

InDesign Tools Overview InDesign Tools Overview REFERENCE If your palettes aren t visible you can activate them by selecting: Window > Tools Transform Color Tool Box A Use the selection tool to select, move, and resize objects.

More information

CPSC Tutorial 6

CPSC Tutorial 6 CPSC 481 - Tutorial 6 More WPF (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, Sowmya Somanath, and Kevin Ta) Introduction Contact Info li26@ucalgary.ca Please

More information

Creating Buttons and Pop-up Menus

Creating Buttons and Pop-up Menus Using Fireworks CHAPTER 12 Creating Buttons and Pop-up Menus 12 In Macromedia Fireworks 8 you can create a variety of JavaScript buttons and CSS or JavaScript pop-up menus, even if you know nothing about

More information

CS3240 Human-Computer Interaction Lab Sheet Lab Session 5 Navigation Framework

CS3240 Human-Computer Interaction Lab Sheet Lab Session 5 Navigation Framework CS3240 Human-Computer Interaction Lab Sheet Lab Session 5 Navigation Framework CS3240 Lab SEM 1 2009/2010 Page 1 Overview In this lab, students will familiarize themselves with creating and get to learn

More information

NE Fundamentals of XAML and Microsoft Expression Blend

NE Fundamentals of XAML and Microsoft Expression Blend NE-10553 Fundamentals of XAML and Microsoft Expression Blend Summary Duration 3 Days Audience Developers Level 200 Technology Microsoft Expression Blend Delivery Method Instructor-led (Classroom) Training

More information

LAYOUT. Chapter 3 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon

LAYOUT. Chapter 3 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon LAYOUT Chapter 3 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon - 2014 Loading and Compiling XAML (See Codes in your Textbook) There are three distinct coding

More information