Visual Basic (Declaration) | |
---|---|
Public Event PropertyChanged As PropertyChangedEventHandler |
C# | |
---|---|
public event PropertyChangedEventHandler PropertyChanged |
Perfomance of your application can be negatively impacted by putting a lot of intensive programming logic in the Map.PropertyChanged Event. It is a best practice to only put essential code for your coding customization in the Map.PropertyChanged Event.
The importance of the PropertyChanged Event is to allow developers to listen for when a particular Non-Dependency Property has changed and thereby write custom code to respond to that change.
In general there are two types of Properties on a Class, Non-Dependency Properties (otherwise known as a "Property" in classic .NET Programming) and Dependency Properties. Non-Dependency Properties, depending on their access level, get and set values. Dependency Properties enhance Non-Dependency Properties by holding a default value (with a built in mechanism for Property value validation and automatic notification for changes in Property value) and allowing for Binding in code-behind or XAML.
The PropertyChanged Event provides the mechanism for trapping when the more basic Non-Dependency Properties values change. To detect when a Dependency Property changes, use Data Binding.
Non-Dependency Properties are those that do not have corresponding Fields in the API Reference documentation for a specific Class. In the case of the Map Class, the Non-Dependency Properties are:
Dependency Properties have corresponding Fields in the API Reference documentation for a specific Class. In the case of the Map Class, the Dependency Properties are:
- Map.IsLogoVisible
- Map.Layers
- Map.PanDuration
- Map.Rotation
- Map.SnapToLevels
- Map.TimeExtent
- Map.ZoomDuration
- Map.ZoomFactor
In some cases Map Properties will have matching Events that could also be used to detect changes; rather than using the Map.PropertyChanged Event you could use matching Event directly to perform some custom coding. In the case of the Map Control the following Properties have matching Events:
Property | Event |
---|---|
Map.Extent | Map.ExtentChanged |
Map.Rotation | Map.RotationChanged |
NOTE: Due to internal implementations you may find that some Dependency Properties do in fact fire a PropertyChanged Event notification. These are exceptions rather than the rule. In the case of the Map Class, the: Layers Property, Rotation Property, and TimeExtent Property do fire notifications in the PropertyChanged Event although they are Dependedncy Properties.
Finding when a specific Layer changes in the Map.Layers LayerCollection (i.e. adding a new layer, removing an existing layer, or clearing all the layers) cannot be detected by the Map.PropertyChanged Event. The Map.PropertyChanged Event will only fire for the Map.Layers Property when the Map.Layers is set to Nothing/null or set to a new instance of a LayerCollection object. In order to detect when layers are added, removed, cleared from the exisiting Map.Layers Property use the LayerCollection.CollectionChanged Event.
You may notice that the Map.PropertyChanged Event fires (utilizing the Extent Property) numerous times for a single Pan or Zoom In/Out operation. This is by design and is part of the user experience. It is the Map.PanDuration and Map.ZoomDuration Properties that control how often the Map.PropertyChanged Event fires showing changes for the Map.Extent Property. The default Map.PanDuration and Map.ZoomDuration Properties is set to 0.75 seconds and this gives the appearance of a highly responsive Map Control display. The Map.PanDuration and Map.ZoomDuration Properties can be set to zero (0) and will provide a more static look and feel of the Map Control refreshing images as they come in from a service. Consequently, setting the Map.PanDuration and Map.ZoomDuration Properties to zero (0) will cause the Map.PropertyChanged Event to only fire once per layer in the Map Control as the user performs a single Pan of Zoom In/Out.
The event handler receives an argument of type PropertyChangedEventArgs containing data related to this event. The following PropertyChangedEventArgs properties provide information specific to this event.
Property | Description |
---|---|
PropertyName |
How to use:
Use the standard Zoom In/Out and Pan, keyboard and mouse actions, to see how the PropertyChanged Event provides information for the PropertyChangedEventArgs.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | Copy Code |
---|---|
<Grid x:Name="LayoutRoot" > <!-- Add a Map control with an ArcGISTiledMapServiceLayer and an ArcGISDynamicMapServiceLayer. Specify the use of the PropertyChanged Event. --> <esri:Map Background="White" HorizontalAlignment="Left" Name="Map1" VerticalAlignment="Top" Height="400" Width="400" PropertyChanged="Map1_PropertyChanged" Margin="2,76,0,0"> <esri:ArcGISTiledMapServiceLayer ID="MyLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" /> <esri:ArcGISDynamicMapServiceLayer ID="DynamicLayer" Opacity="0.5" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer"/> </esri:Map> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="61" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="531" TextWrapping="Wrap" Margin="2,9,0,0" Text="Use the standard Zoom In/Out and Pan, keyboard and mouse actions, to see how the PropertyChanged Event provides information for the PropertyChangedEventArgs." /> <!-- Add a Label and ListBox to show which Map.PropertyChanged notifications have occured. --> <sdk:Label Content="PropertyName:" Margin="420,74,20,390" HorizontalAlignment="Left" VerticalAlignment="Top"/> <ListBox x:Name="PropertyName" Margin="420,96,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="160" Height="372" /> </Grid> |
C# | Copy Code |
---|---|
private void Map1_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { // Display the results from the Map.PropertyChanged Event. PropertyName.Items.Add(e.PropertyName); } |
VB.NET | Copy Code |
---|---|
Private Sub Map1_PropertyChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) ' Display the results from the Map.PropertyChanged Event. PropertyName.Items.Add(e.PropertyName) End Sub |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8