Click or drag to resize
LayerInitializeAsync Method
Loads the metadata for this layer based on the current configuration.

Namespace: Esri.ArcGISRuntime.Layers
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: (
public Task InitializeAsync()

Return Value

Type: Task
Completion Task

Demonstrates implementing logic which is dependent on the layer collection being initialized.

Code example using the Layer.InitializeAsync Event.

<Window x:Class="LayersInitialized.MainWindow"
        Height="600" Width="800">


        <!-- Add a MapView Control. -->
        <esri:MapView x:Name="MapView1">

            <!-- Add a Map. -->
            <esri:Map x:Name="MyMap">

                <!-- Add an ArcGISTiledMapServiceLayer. -->
                <esri:ArcGISTiledMapServiceLayer ID="WorldStreetMap" 
                      ServiceUri="" />

        <Border HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" Padding="5" Background="White" 
                BorderBrush="Black" BorderThickness="1">
                <DropShadowEffect />
            <StackPanel Orientation="Vertical">

                <!-- Set to the Binding to the TextBox.Text Property. This way when things change in the code-behind 
                it will be displayed in the GUI. -->
                <TextBlock Width="150" Margin="5" Text="{Binding LayersInitializedProperty}" 
                           Background="Black" Foreground="White"/>


SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "LayersInitialized.MainWindow" to be just "MainWindow".

using System.Linq;

// NOTE: This sample demonstrates implementing logic which is dependent on the layer collection being initialized. An
// MVVM style of programming is used.

namespace LayersInitialized
    public partial class MainWindow : System.Windows.Window, System.ComponentModel.INotifyPropertyChanged

        // Inherit the functionality from the basic Window Class.

        // Enable adding the functionality of INotifyPropertyChanged interface into the sample. We will use it for updating
        // information in the TextBox defined in Xaml as to whether the ArcGISTiledMapServiceLayer in the MapView Control 
        // has initialized.

        // Adding the INotifyPropertyChanged interface was performed by the developer. This interface is not automatically added 
        // as part of plumbing code. Adding in the INotifyPropertyChanged interface allows the 'LayersInitializedProperty' to 
        // receive notifications.
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        // Global variable that holds text that inform the user the state of the ArcGISTiledMapServiceLayer initialization.
        private string _layersInitialized = "No Initialized";

        // Gets or sets the text indicating whether the ArcGISTiledMapServiceLayer is initialized or not. By default the text will 
        // be: "No Initialized", later once the ArcGISTiledMapServiceLayer is initialized the text will be: "Initialized".
        public string LayersInitializedProperty
                return _layersInitialized;
                _layersInitialized = value;

                if (PropertyChanged != null)
                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("LayersInitializedProperty"));

        public MainWindow()


            // Set up the Binding DataContent to this application. This action causes the LayersInitializedProperty to be invoked.
            // NOTE: the action of invoking the LayersInitializedProperty will not occur immediately when stepping thru via the 
            // debugger. The 'MainWindow' which is (this) runs on the GUI thread, needs to wait a while for CPU time to update the Binding.
            // When the debugger has an opportunity catch up on the thread the LayersInitializedProperty will have the 
            // _layersInitialized variable set to "No Initialized" and hence what is displayed in the GUI TextBox.text Property. Most
            // likely you will not see the LayersInitializedProperty Property execute until after the await line is hit in the 
            // HandleLayerInitialized function because this is when the compiler has time to process the GUI thread!
            DataContext = this;

            // Call the function that determines when all of the layers in the Map have initialized.
            System.Threading.Tasks.Task myTask = HandleLayersInitialized();


        public async System.Threading.Tasks.Task HandleLayersInitialized() 
            // This next line of code is important. The Task.WhenAll is a Microsoft function that ascertains when a Task has 
            // completed. By using a LINQ query for MapView1.Map.Layers.Select we cycle through all of the Layers to know if we have 
            // a successful layer completion, an error or a cancel.
            await System.Threading.Tasks.Task.WhenAll(MapView1.Map.Layers.Select(layer => layer.InitializeAsync()).ToArray());

            // NOTE: at this exact moment the _layersInitialized global variable equals "No Initialized" and hence the 
            // Binding in the Xaml to the TextBox.Text will display: "No Initialized".

            // Once this next line of code executes, the LayersInitializedProperty will be called again and this time the 
            // _layersInitialized global variable will be set to the text "Initialized!" and the PropertyChanged Event will
            // be raised with affect the TextBox.Text binding to display the text: "Initialized!".
            LayersInitializedProperty = "Initialized!";           

See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
ArcGISDynamicMapServiceLayerImageFormatShows changing the return ImageFormat for ArcGISDynamicMapServiceLayer and how that appears visually in the Map.
ArcGISDynamicMapServiceLayerXamlAndCodeBehindShows creating an ArcGISDynamicMapServiceLayer in XAML and via code-behind. The ArcGISDynamicMapServiceLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Copyright) using the Async/Task framework.
ArcGISImageServiceLayerXamlAndCodeBehindShows adding an ArcGISImageServiceLayer via XAML and code-behind. The ArcGISImageServiceLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Description) using the Async/Task framework.
FeatureLayerXamlAndCodeBehindShows creating a FeatureLayer in XAML and via code-behind. The FeatureLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Copyright) using the Async/Task framework.
GeoRSSLayerWindowCreates a GeoRssLayer based on the United States Geological Survey earthquake feed and assigned a SimpleRenderer.
GraphicsLayerWindowDemonstrates various Graphics and GraphicsLayer related actions.
LayerCollectionDemonstrates the work-flow of creating a layer dynamically via code-behind. The process of a layer: (1) initializing, (2) determining when initialization is complete, and (3) error trapping for bad initialization is described in detail.
LayerDrawingOptionsDemonstrates changing the rendering of the first sub-layer of an ArcGISDynamicMapServiceLayer using the Dynamic Layer capabilities of ArcGIS Server 10.1 and higher.
LayersInitializedDemonstrates implementing logic which is dependent on the layer collection being initialized.
MapView_SpatialReferenceDemonstrates reseting the MapView.SpatialReference by setting it to a new Map.
RoutingPointToPointDemonstrates simple point to point routing between two input locations.
RoutingWithBarriersShows routing and re-routing around user defined point, polyline, and polygon barriers.
RoutingWithDirectionsInteraction logic for RoutingWithDirections.xaml