EziData Solutions

Web, NET and SQL Server

Handling Pushpins selection with the WP7 Map control

As mentioned in the previous post, one of the benefits of using your own custom business objects as the data source for your Map control Pushpin layer is that you can access all the information about the item you select.

So how do we get back a single Camera object when a user presses on a pushpin? Well thankfully this is very easy. By using a List<Camera> as the ItemSource for the MapsItemControl control containing our Pushpins we are able to extract the data back when the user presses the Pushpin.

There are a number of methods you can use that are triggered when the user clicks or taps on the screen, but in this example we will use the new ‘Tap’ event, made available in the Mango release. The map xaml has been covered in the previous post, but now all we need to do is add the Tap event handler such as:

<my:Pushpin Location="{Binding Location}" Tap="Pushpin_Tap" >


The key to unlocking all the goodness obtained by binding the pushpins to your own objects is to realise that the DataContext of the Pushpin actually contains your business object.

private void Pushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e)


var pushpin = sender as Pushpin;


Camera cam= (Camera)pushpin.DataContext;



In this example we can direct cast the Pushpin.DataContext to our business object, which in this example is called Camera. Once we have a Camera object, we can access any of the properties and methods associated with it.

Obviously you could do a lot more than simply displaying a message when the Pushpin is selected, for example you could navigate to another page displaying information relevant to the selected Pushpin.


Posted: Dec 23 2011, 07:14 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: WP7

Using Business Objects with the WP7 Map Control

One aspect of creating and adding pushpins to the Windows Phone 7 Map control that turned out to be a welcome revelation to me is that most geo-centric Business Objects can be used as the data source for the pushpin layer with little or no modification.

In a previous post we looked at how easy it was to add a single pushpin to the Map control. If we look at that method again, we see that all we really need is a geographical location. This means that as long as your object has a Latitude and Longitude, you can use it as a pushpin.

This was very handy in TrafficMATE especially when displaying camera locations on a map. The Camera object model we created already contained the Lat/Long of the camera. This meant that I could easily use a List<Camera> object as the ItemSource for the pushpin layer.

Here’s the xaml for a map showing camera locations.

<my:Map x:Name="CameraMap"

    CredentialsProvider="{Binding CredentialsProvider}"





        <SolidColorBrush Color="{StaticResource PhoneForegroundColor}"/>


    <my:MapItemsControl x:Name="PushpinItems" Height="300">



                <my:Pushpin Location="{Binding Location}" >






The code that is of interest to us is the section defining the MapItemsContol named PushpinItems. Just like the other WP7 databindable controls, the MapItemsControl supports an ItemTemplate, which in this example is made up of Pushpin controls.

The Location property of the Pushpin, which is of type GeoCoordinate, is bound to a field in our data source called ‘Location’. All we need to support binding is ensure our business object exposes a GeoCoordinate property and we are good to go. A simplified version of the Camera object is shown below.

public class Camera


    public string Name { get; set; }

    public string Description { get; set; }

    public double Latitude { get; set; }

    public double Longitude { get; set; }


    public GeoCoordinate Location


        get { return new GeoCoordinate(this.Latitude, this.Longitude); }



With the help of an async call to a webservice, I populated a List<Camera> with relevant results and was able to set the ItemSource for the pushpin layer using something like:

PushpinItems.ItemsSource = cameras;

The key benefit of binding your objects directly to the pushpin layer is that you have direct access to the object whenever you select a pushpin. There is no need to make a second trip to the webservice when the user selects a pushpin - you already know everything there is to know about the underlying object. In a future post, I will explore how you can retrieve the underlying information from a Pushpin created using your business objects.

Posted: Dec 22 2011, 05:09 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Windows Phone 7 | WP7

Windows 8 Developer Preview

Loading the Windows 8 Developer Preview

After downloading the Windows 8 Developer preview and attempting to install the OS on both the VMWare Player and Oracle VM, I soon found out that this was not going to be an easy option. Oracle VM got me the closest and at least looked like it was installing Windows 8, but in the end, neither worked.

My next option was to install the preview OS on my old desktop PC, which originally had Windows XP Media Centre, but had been dual boot with Windows 7 since I added a second hard-drive.

After going through the steps to make a bootable USB using the Windows 7 USB/DVD Download Tool, I fired up my 5-year old AMD powered PC and selected the appropriate USB drive in the BIOS.

The OS installed very quickly, although it did restart a couple of times. On one restart it asked me to choose between the original Windows 7 installation or a new Windows 8, which I happily accepted.

After the initial installation, I selected the default 'Use express settings' option from the Settings screen and entered my windows live email address in the next screen.

On the 'Keep your account safer' screen I was surprised to find that Microsoft think they know my mobile phone number better than I do and after entering the correct , full number several times, only to be told that it was not correct for my country/region, I thought I might have been getting it wrong all these years. Turns out, MS wanted me to drop the leading zero(0) from the number. It also pulled me up on the secret question answer when I only entered 4 characters – I guess I will have to rename my first pet (may they rest in peace). I eventually decided not to bother with the secret question and I was able to proceed without a hitch.

So after a fairly brief installation process, I was logged into my Windows 8 developer preview, which it said was customised just for me based on my Windows Live account details. First button I tried was the weather button, only to find that it displayed Anaheim, CA – quite a few thousand miles from my home in Brisbane.

My next challenge was finding out how to exit from the weather app and go back to the main start screen. After trying every key on the keyboard, I discovered that the Windows Key is the answer – I guess I am used to the dedicated back button on Windows Phone 7.

Next app that looked interesting was the tweet@rama app – but it didn't want to play, so I headed back to the start screen for something better. Jumping into NearMe, I was again frustrated by the fact that the closest matches were in California, but I guess that must just be a sign to relocate.

After a restart, what startled me most was the speed at which that login screen came up. I mean this PC is old and not all that fast, so when I showed the login screen after only 15 seconds, I was completed unprepared.

Cold boot to 'Choose an operating system' screen 34.8 sec, login screen to start screen 16.1 sec. So even on my old clunker, I am fully online in less than a minute.


Posted: Dec 16 2011, 06:06 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Windows 8 | W8