Hello,
I use the XamMap control with a ValueTemplate for my map elements. I added a context menu in the ValueTemplate of each elements.
I use a Routed Command on the MenuItem but I also tried the click event.
On the click event, the sender and the source are the MenuItem element itself.
On the routed command the sender is the Window and the source is the XamMap control.
How can I retrieved the corresponding map element on the click event or routed command execute method ?
Thanks.
DataContext was the right property to use.
Thanks
Hi The_badger_man,
You could try an approach similar to the following.
XAML: <Grid> <Grid.RowDefinitions> <RowDefinition Height="400"/> <RowDefinition Height="*"/> </Grid.RowDefinitions>
<ListBox x:Name="lstClickedElement" Height="250" Width="400" Grid.Row="0"/>
<igMap:XamMap x:Name="map1" Grid.Row="1"> <igMap:XamMap.Layers> <igMap:MapLayer x:Name="statesLayer"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="/../../Shapefiles/usa/usa_st" DataMapping="Name=STATE_NAME; Value=POP1997; Caption=STATE_NAME"/> </igMap:MapLayer.Reader>
<igMap:MapLayer.ValueTemplate> <DataTemplate> <Menu x:Name="menu1" Height="22" Width="100"> <MenuItem Header="Item1" Click="MenuItem_Click"/> </Menu> </DataTemplate> </igMap:MapLayer.ValueTemplate> </igMap:MapLayer> </igMap:XamMap.Layers> </igMap:XamMap> </Grid>
CB: private void MenuItem_Click(object sender, RoutedEventArgs e) { var mnuItem = (MenuItem)sender; var element = (MapElement)(mnuItem.DataContext);
this.lstClickedElement.Items.Add(String.Format("Clicked on {0}.", element.Caption)); }
Hope that helps,Milana Zhileva