This sample demonstrates the InfoWindow control. The InfoWindow
control allows displaying content placed at a specific anchor point
on the Map control. The Content property of an InfoWindow can be
any type of object, such as a string, a UIElement, or a DateTime.
For this sample, if the user clicks over a US State the name of the
State will appear in the InfoWindow. The sample shows how to
add Content to an existing InfoWindow defined in XAML using
code-behind and how to create a new InfoWindow wholly in
code-behind and populate its Content.
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Toolkit;
using System.ComponentModel;
namespace ArcGISWPFSDK
{
publicpartialclass LocalInfoWindowSimple : UserControl, INotifyPropertyChanged
{
publicevent PropertyChangedEventHandler PropertyChanged;
privatebool _isBusy = true;
publicbool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IsBusy"));
}
}
}
public LocalInfoWindowSimple()
{
InitializeComponent();
DataContext = this;
MyMap.Layers.LayersInitialized += (o, evt) =>
{
IsBusy = false;
};
}
privatevoid 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<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;
}
}
privatevoid MyInfoWindow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MyInfoWindow.IsOpen = false;
}
}
}
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Toolkit
Imports System.ComponentModel
Namespace ArcGISWPFSDK
PartialPublicClass LocalInfoWindowSimple
Inherits UserControl
Implements INotifyPropertyChanged
PublicEvent PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private _isBusy AsBoolean = TruePublicProperty IsBusy() AsBooleanGetReturn _isBusy
EndGetSet(value AsBoolean)
_isBusy = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("IsBusy"))
EndSetEndPropertyPublicSubNew()
InitializeComponent()
AddHandler MyMap.Layers.LayersInitialized, AddressOf map_LayersInitialized
EndSubPrivateSub MyMap_MouseClick(sender AsObject, e As ESRI.ArcGIS.Client.Map.MouseEventArgs)
Dim featureLayer As FeatureLayer = TryCast(MyMap.Layers("MyFeatureLayer"), FeatureLayer)
Dim screenPnt As System.Windows.Point = MyMap.MapToScreen(e.MapPoint)
' Account for difference between Map and application originDim generalTransform As GeneralTransform = MyMap.TransformToVisual(Application.Current.MainWindow)
Dim transformScreenPnt As System.Windows.Point = generalTransform.Transform(screenPnt)
Dim selected As IEnumerable(Of Graphic) = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt)
ForEach g As Graphic 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
ReturnNextEndSubPrivateSub MyInfoWindow_MouseLeftButtonUp(sender AsObject, e As System.Windows.Input.MouseButtonEventArgs)
MyInfoWindow.IsOpen = FalseEndSubPrivateSub map_LayersInitialized(sender AsObject, e As EventArgs)
DataContext = Me
IsBusy = FalseEndSubEndClassEndNamespace