void GraphicClick(object sender, GraphicMouseButtonEventArgs e)
{
Graphic gra = e.Graphic;
MapPoint myMapPoint = new MapPoint();
myMapPoint = gra.Geometry as MapPoint;
InfoWindow myInfoWindow = new InfoWindow();
myInfoWindow.Content = e.Graphic.Attributes;
myInfoWindow.Anchor = myMapPoint;
myInfoWindow.IsOpen = true;
myInfoWindow.Map = MapApplication.Current.Map;
myInfoWindow.ContentTemplate = LayoutRoot.Resources["InfoWindowTemplate"] as System.Windows.DataTemplate;
LayoutRoot.Children.Add(myInfoWindow);
myInfoWindow.MouseLeftButtonDown += new MouseButtonEventHandler(MyInfoWindow_MouseLeftButtonDown);
}
<Grid.Resources>
<DataTemplate x:Key="InfoWindowTemplate" x:Name="InfoWindowTemplate">
<StackPanel x:Name="InfoStack" Orientation="Vertical" Margin="10,10,10,10" Background="Transparent">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Background="Transparent">
<TextBlock Text="Field Name: " FontWeight="Bold"/>
<TextBlock x:Name="textValue" >
</StackPanel>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<DataTemplate x:Key="MyDynamicMapInfoWindowTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding Keys}" Grid.Column="0" />
<ItemsControl ItemsSource="{Binding Values}" Grid.Column="1" />
</Grid>
</DataTemplate>
foreach (Graphic g in selected)
{
MyInfoWindow.Anchor = e.MapPoint;
MyInfoWindow.IsOpen = true;
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
MyInfoWindow.Content = g.Attributes;
return;
}
InfoWindow window = new InfoWindow()
{
Anchor = e.MapPoint,
Map = MyMap,
IsOpen = true,
ContentTemplate = LayoutRoot.Resources["MyDynamicMapInfoWindowTemplate"] as System.Windows.DataTemplate,
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
Content = e.MapPoint
};
<esri:InfoWindow x:Name="MyInfoWindow"
Padding="2"
CornerRadius="20"
Background="LightSalmon"
Map="{Binding ElementName=MyMap}"
ContentTemplate="{StaticResource MyDynamicMapInfoWindowTemplate}"
MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />