Pushpin Name on Click Event Silverlight 4 RRS feed

  • Question

  • Hi All,

    I have bing maps implemented in my application and basically i need to show additional data in a panel when a Pushpin is clicked. I have a custom class which inherits from pushpin class...I am using MVVM and was successful to show pushpin's on the map. Problem is i need to know the name of the pushpin to fill data in my panel for that item when i click on a pushpin which i am not able to

    Here is my XAML:


            <DataTemplate x:Key="LogoTemplate">
                <m:Pushpin x:Name="Test"  m:MapLayer.Position="{Binding Location}" MouseLeftButtonDown="MapItemsControl_MouseLeftButtonDown" >
                        <TextBlock x:Name="TextBlock_ServiceVehicle"  Text="{Binding ServiceVehicle}"></TextBlock>

     <m:Map x:Name="RadMap1" Width="940" Height="680" Grid.Column="1"  Grid.Row="0" Grid.RowSpan="2" ZoomLevel="2"
                   CredentialsProvider="AlTJi_bZz5-h4dlv2MowdBhTLSoAw1d_yRuuWe_04UcfbH9WgxopzZfqtCo-dZGT" >
                    <m:MapLayer x:Name="PushPinLayer">
                        <Canvas x:Name="ContentPopup" Visibility="Collapsed"
      Opacity="0.85" >
                            <Rectangle x:Name="ContentPopupRectangle" Fill="White"
      Canvas.Left="0" Canvas.Top="0" Height="100"
      Width="300" RadiusX="20" RadiusY="20"/>
                            <StackPanel Canvas.Left="10" Canvas.Top="10">
                                <TextBlock x:Name="ContentPopupText" 
        FontSize="12" FontWeight="Bold"
        TextWrapping="Wrap" Width="250">
                    <m:MapItemsControl x:Name="ItemsControl"   ItemsSource="{Binding LiveGPSCollection}"   ItemTemplate="{StaticResource LogoTemplate}"/>

    My code behind:

     private void MapItemsControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                Microsoft.Maps.MapControl.Pushpin pin = sender as Microsoft.Maps.MapControl.Pushpin;
                //string test = pin.Tag.ToString();

                if (radExpander.IsExpanded)
                    radExpander.IsExpanded = false;
                    radExpander.IsExpanded = true;


    click event is raised when i click the pushpin but "pin" in the event as you can see in the code is always null.....All i need is to access this value on click event   Text="{Binding ServiceVehicle}".


    Any help is greatly appreciated.


    Wednesday, September 15, 2010 3:17 PM


  • If you still haven't figured this out, I can try helping out.

    I have done something like this, but I didn't do binding. I relied heavily on pin.Name and pin.Tag and it worked fine. I'm still looking at your code, but before I wonder about other things, let me confirm if I'm understanding this correctly -- Where are you assigning any value to your pin.Name and/or pin.Tag?

    I did most of the stuff from the code side, so maybe this can give you some idea:

    I have a AddPin() function that adds pins to the map as something like this:




    foreach(string man in People) // People is a collection, in my case a list


    Pushpin pin = new Pushpin();

    pin.Name = man;

    myMap.AddChild(pin, someLocation);

    pin.MouseLeftButtonDown += new MouseButtonEventHandler (pin_MouseLeftButtonDown);



    //now on the mouse down event  handler

    pin_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)


    Pushpin pin = (Pushpin) sender;

    string name = pin.Name; // or Pin.Tag if that's what you're using

    //so if you're trying to display the Name on the panel, I'm assuming there's some sort of textblock or some control where the pin name can be assigned. For that, you'd do (within this same event handler)

    TheTextBlock.Text = name;


    Hope that will help atleast a bit :)

    Thursday, September 30, 2010 8:26 PM