private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { FeatureLayer featureLayer = MyMap.Layers["WindLayer"] as FeatureLayer; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); // Account for difference between Map and application origin GeneralTransform generalTransform = MyMap.TransformToVisual(null); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); int tolerance = 20; Rect screenRect = new Rect(new Point(transformScreenPnt.X - tolerance / 2, transformScreenPnt.Y - tolerance / 2), new Point(transformScreenPnt.X + tolerance / 2, transformScreenPnt.Y + tolerance / 2)); IEnumerable <Graphic> selected = featureLayer.FindGraphicsInHostCoordinates(screenRect); 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; } }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); // Account for difference between Map and application origin GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable <Graphic> selected = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); 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, Placement = InfoWindow.PlacementMode.Auto, ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate, //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate Content = e.MapPoint }; LayoutRoot.Children.Add(window); }