Click or drag to resize
Code Example - ArcGISImageServiceLayerXamlAndCodeBehind

Shows 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.

Code Example
ArcGISImage Service Layer Xaml And Code Behind

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="ArcGISImageServiceLayerXamlAndCodeBehind.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Vertical">

                <!-- TextBlock to provide the instructions on how to use the sample code. It will be 
                populated with instructions in the code-behind when the application loads. -->
                <TextBlock Height="91" HorizontalAlignment="Left" x:Name="TextBlock1" VerticalAlignment="Top" 
                           Width="770" TextWrapping="Wrap"  Margin="10,2,0,0" ><InlineUIContainer>
                  </InlineUIContainer></TextBlock>

            </StackPanel>
            <StackPanel Orientation="Vertical">

                <!-- Button to add an ArcGISImageServiceLayer via code-behind. -->
                <Button Content="Add another ArcGISImageServiceLayer (via code-behind) for the specified Url." 
                        x:Name="Button1" Click="Button1_Click" Width="780" HorizontalAlignment="Left"/>

            </StackPanel>
            <StackPanel Orientation="Horizontal">

                <!-- A MapView Control to display various GIS layers. -->
                <esri:MapView x:Name="MapView1" Width="392" Height="450" VerticalAlignment="Top" Margin="2,2,2,2">

                    <!-- A Map. -->
                    <esri:Map  x:Name="Map1" >

                        <!-- Add an ArcGISImageServiceLayer via Xaml. -->
                        <esri:ArcGISImageServiceLayer ID="CaliforniaDEM" 
                              ServiceUri="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/CaliforniaDEM/ImageServer" />

                    </esri:Map>
                </esri:MapView>

                <StackPanel Orientation="Vertical" >

                    <!-- TextBox to display information about the various layers in the Map. -->
                    <TextBox x:Name="TextBox1" TextWrapping="Wrap" Height="452" Width="379" Margin="2,2,2,2"/>

                </StackPanel>

            </StackPanel>
        </StackPanel>
    </Grid>

</Window>

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 "ArcGISImageServiceLayerXamlAndCodeBehind.MainWindow" to be just "MainWindow".

namespace ArcGISImageServiceLayerXamlAndCodeBehind
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            // This call is required by the designer.
            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.

            // Provide instructions on how to use the sample. 
            TextBlock1.Text = "When the application loads an ArcGISImageServiceLayer will " + 
                              "automatically be added to the Map (it was specified in XAML). Click the Button to add another " + 
                              "ArcGISimageServiceLayer to the Map (it will be added via code-behind). The ID  and description " + 
                              "information of each layer will displayed in the TextBox.";

            // Create a Geometry based on an Envelope set to a particular extent of Northern California / Oregon using a WebMercator Spatial Reference.
            Esri.ArcGISRuntime.Geometry.Geometry myGeometry = new Esri.ArcGISRuntime.Geometry.Envelope(-14024888, 4467120, -12873427, 5788950, Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator);

            // Set the initial extent of the Map using the InitialViewpoint Property to that of our Geometry.
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myGeometry);

            // Call our custom 'async' function to display information about the ArcGISImageSericeLayer that was added in XAML.
            Init();
        }

        public async void Init()
        {
            // This function will display information about the ArcGISImageServiceLayer that was added in XAML.

            // Get the ArcGISImageServiceLayer by it's index number.        
            Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer myArcGISImageServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer)MapView1.Map.Layers[0];

            // Initialize the ArcGISImageServiceLayer which allows for obtain various Property information.
            await myArcGISImageServiceLayer.InitializeAsync();

            // Get the ID of the ArcGISImageServiceLayer.
            string myID = myArcGISImageServiceLayer.ID;

            // Create a StringBuilder object to hold information about the ArcGISImageServiceLayer.
            System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();

            // Add the ID of the ArcGISImageServiceLayer to the StringBuilder.
            myStringBuilder.Append("The 1st ArcGISImageServiceLayer was added via XAML and it's ID is: " + myID + System.Environment.NewLine);

            // Get the MapServiceInfo details about the ArcGISImageServiceLayer.
            Esri.ArcGISRuntime.ArcGISServices.ImageServiceInfo myImageServiceInfo = myArcGISImageServiceLayer.ServiceInfo;

            // Get the description information about the ArcGISImageServiceLayer and add to the StringBuilder.
            string myDescription = myImageServiceInfo.Description;
            myStringBuilder.Append(myDescription + System.Environment.NewLine);

            // Display the results of the StringBuilder text to the user.
            TextBox1.Text = myStringBuilder.ToString();
        }

        private async void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // This function will add an ArcGISImageServiceLayer to the Map via code behind.

            // Create a new Uri that point to an ArcGISImageServiceLayer.
            System.Uri myUri = new System.Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer");

            // Create a new instance of an ArcGISImageServiceLayer.
            Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer myArcGISImageServiceLayer = null;
            myArcGISImageServiceLayer = new Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer();

            // Set the Uri and ID of the ArcGISDynamicMapSericveLayer.
            myArcGISImageServiceLayer.ServiceUri = myUri.ToString();
            myArcGISImageServiceLayer.ID = "CascadeLandsat";

            // Add the ArcGISImageServiceLayer to the Map.
            MapView1.Map.Layers.Add(myArcGISImageServiceLayer);

            // Initialize the ArcGISImageServiceLayer which allows for obtain various Property information.
            await myArcGISImageServiceLayer.InitializeAsync();

            // Get the ID of the ArcGISImageServiceLayer.
            string myID = myArcGISImageServiceLayer.ID;

            // Create a StringBuilder object to hold information about the ArcGISImageServiceLayer.
            System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();
            myStringBuilder.Append(TextBox1.Text + System.Environment.NewLine);
            myStringBuilder.Append(System.Environment.NewLine);

            // Add the ID of the ArcGISImageServiceLayer to the StringBuilder.
            myStringBuilder.Append("The 2nd ArcGISImageServiceLayer was added via code-behind and it's ID is: " + myID + System.Environment.NewLine);

            // Get the MapServiceInfo details about the ArcGISImageServiceLayer.
            Esri.ArcGISRuntime.ArcGISServices.ImageServiceInfo myImageServiceInfo = myArcGISImageServiceLayer.ServiceInfo;

            // Get the description information about the ArcGISImageServiceLayer and add to the StringBuilder.
            string myDescription = myImageServiceInfo.Description;
            myStringBuilder.Append(myDescription + System.Environment.NewLine);

            // Display the results of the StringBuilder text to the user.
            TextBox1.Text = myStringBuilder.ToString();
        }
    }
}