Runewake2
Runewake2

Reputation: 481

How to display a DataBound Pushpin on Windows Phone

I am trying to create a pushpin on Windows Phone that shows a number of locations, including there name, rating and more. I have searched MSDN, Stack Overflow and other sites for a solution to this and found only partial answers.

This is my current attempt. It doesn't work at all. It does create a pushpin, but it is not changed to show a grid or any of the other elements. Instead it shows a blank pushpin in the top left of the map.

<mi:Map x:Name="map" Margin="-12,0" d:LayoutOverrides="Width" CredentialsProvider="Something else goes here :)">
   <mi:MapItemsControl ItemsSource="{Binding Pushpins}">
      <mi:MapItemsControl.ItemTemplate>
         <DataTemplate>
            <mi:Pushpin Location="{Binding Location}">
               <Grid Background="{Binding Background}">
                  <TextBlock Text="{Binding Name}" Margin="6,0"/>
                  <ProgressBar Maximum="5" Value="{Binding Rating}"/>
               </Grid>
             </mi:Pushpin>
          </DataTemplate>
       </mi:MapItemsControl.ItemTemplate>
    </mi:MapItemsControl>
 </mi:Map>

How can I get the above code or something like it to work?

My previous solution involved creating the elements with code, the problem with that is that it got messy beyond a few pins and could not easily be used to get other information (such as a Stores URL).

Edit: Some extra information on the code behind everything.

public struct PushpinModel
{
    public GeoCoordinate Location { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }
    public float Rating { get; set; }
    public Brush Background { get; set; }
}

These pushpin models are added to the Pushpin's observable collection with the AddPin method:

public void AddPin(GeoCoordinate coord, string Title, string url, float rating, Brush background)
{
    Pushpins.Add(new PushpinModel { Location = coord, Name = Title, Rating = rating, Url = url, Background = background} );
}

My GeoCoordinateWatcher calls the watcher_PositionChanged event when it's position is changed. This adds a pushpin at the users location.

Currently the ZoomToUser() function is being called, but the pushpin is not appearing.

Upvotes: 0

Views: 902

Answers (1)

Igor Kulman
Igor Kulman

Reputation: 16361

This looks wrong

 <mi:MapItemsControl ItemsSource="Pushpins">

if it is a property of the datacontext it should be

 <mi:MapItemsControl ItemsSource="{Binding Pushpins}">

Upvotes: 3

Related Questions