I need to have an infoWindow that displays the Outfields of a FeatureLayer. The infoWindow is popping up, but it is popping up no matter where you click on the map and it does not contain any of the content. I have looked through the documentation and the only difference is that instead of using a UserControl, I am using a DialogWindowBase. Below is my XAML and C#.
XAML:
Padding="2"
CornerRadius="20"
Background="{StaticResource PanelGradient}"
Map="{Binding ElementName=My_Map}"
ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}"
MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp">
C#: Here is the C# code that I have that will at least build and allow the infoWindow to appear:
private void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
{
FeatureLayer featurelayer = MyMap.Layers["Water_Valves"] as FeatureLayer;
System.Windows.Point screenPoint = MyMap.MapToScreen(e.MapPoint);
MyInfoWindow.Anchor = e.MapPoint;
MyInfoWindow.IsOpen = true;
}
Here is the way the documentation does it:
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.MainWindow);
System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);
IEnumerable 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;
}
}
When I try to run it while using the generalTransform is says that is cannot do it because it is not an ancestor.
Answer
I found an alternate way to do it that works.
XAML:
Padding="2"
CornerRadius="20"
Background="{StaticResource PanelGradient}"
Map="{Binding ElementName=MyMap}"
ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}">
C#:
MapPoint lastPoint = null;
private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
{
FeatureLayer flayer = sender as FeatureLayer;
MapPoint clickpoint = MyMap.ScreenToMap(e.GetPosition(MyMap));
if (clickpoint != lastPoint)
{
MyInfoWindow.Anchor = clickpoint;
MyInfoWindow.Content = e.Graphic.Attributes;
MyInfoWindow.IsOpen = true;
lastPoint = clickpoint;
}
}
No comments:
Post a Comment