private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { FeatureLayer featureLayer = (FeatureLayer) MyMap.Layers["MyFeatureLayer"]; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> selected = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); //Here is the actual error point. When user clicks outside of the USA selected is null. 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; } }
Solved! Go to Solution.
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { FeatureLayer featureLayer = (FeatureLayer)MyMap.Layers["MyFeatureLayer"]; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> selected = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); //Here is the actual error point. When user clicks outside of the USA selected is null. var selectionEnum= selected.GetEnumerator(); if (!selectionEnum.MoveNext()) { MyInfoWindow.ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as DataTemplate; MyInfoWindow.Anchor = e.MapPoint; MyInfoWindow.IsOpen = true; //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate MyInfoWindow.Content = e.MapPoint; return; } foreach (Graphic g in selected) { MyInfoWindow.ContentTemplate = LayoutRoot.Resources["MyFeatureLayerInfoWindowTemplate"] as DataTemplate; 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 = (FeatureLayer)MyMap.Layers["MyFeatureLayer"]; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> selected = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); //Here is the actual error point. When user clicks outside of the USA selected is null. var selectionEnum= selected.GetEnumerator(); if (!selectionEnum.MoveNext()) { MyInfoWindow.ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as DataTemplate; MyInfoWindow.Anchor = e.MapPoint; MyInfoWindow.IsOpen = true; //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate MyInfoWindow.Content = e.MapPoint; return; } foreach (Graphic g in selected) { MyInfoWindow.ContentTemplate = LayoutRoot.Resources["MyFeatureLayerInfoWindowTemplate"] as DataTemplate; 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; } }