Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET


Download Samples Repository


This sample demonstrates how to search your data using the find task. The sample displays the results on the map and in tabular list view.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.FindTaskSample"
    <Grid x:Name="layoutGrid">
            <esri:SimpleMarkerSymbol x:Key="MarkerSymbol" Size="6" Color="Red" Style="Circle" />
            <esri:SimpleLineSymbol x:Key="LineSymbol" Color="Red" Width="4"  />
            <esri:SimpleFillSymbol x:Key="FillSymbol" Color="#50FF0000">
                    <esri:SimpleLineSymbol Color="Red" Width="2" Style="Solid" />

        <esri:MapView x:Name="MyMapView" WrapAround="True">
            <esri:Map InitialViewpoint="-14675766.357,2695407.734,-6733121.861,6583994.101,102100">
                    ServiceUri="" />
                     ServiceUri="" />
				<esri:GraphicsOverlay ID="graphicsOverlay" />

        <Border Background="White" BorderBrush="Black" BorderThickness="1" 
				Margin="30" Padding="20" Width="325"
                HorizontalAlignment="Right" VerticalAlignment="Top">
				<DropShadowEffect />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />

                <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
                    <TextBlock Text="Find State/City/River:" Margin="0,0,6,0" VerticalAlignment="Center" />
                    <TextBox x:Name="txtFind" Text="Colorado" Width="100" />
                <Button Grid.Row="1" Content="Find" IsDefault="True" Margin="24,8" Click="FindButton_Click" />

                <ProgressBar x:Name="progress" Grid.Row="2" IsIndeterminate="True" Margin="10" Visibility="Collapsed"/>

                <ListView x:Name="resultsGrid" Grid.Row="2" Margin="0,20,0,0" Visibility="Collapsed" ItemsSource="{x:Null}" 
                          SelectionMode="Single" SelectionChanged="resultsGrid_SelectionChanged">
                            <GridViewColumn Header="Layer" DisplayMemberBinding="{Binding LayerName}" Width="50" />
                            <GridViewColumn Header="Field" DisplayMemberBinding="{Binding FoundFieldName}" Width="90" />
                            <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Value}" Width="200" />
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
    /// <summary>
    /// This sample demonstrates how to search your data using the find task. The sample displays the results on the map and in tabular list view.
    /// </summary>
    /// <title>Find</title>
	/// <category>Tasks</category>
	/// <subcategory>Query</subcategory>
	public partial class FindTaskSample : UserControl
        private Symbol _markerSymbol;
        private Symbol _lineSymbol;
        private Symbol _fillSymbol;
		private GraphicsOverlay _graphicsOverlay;

        /// <summary>Construct Find sample control</summary>
        public FindTaskSample()
            _markerSymbol = layoutGrid.Resources["MarkerSymbol"] as Symbol;
            _lineSymbol = layoutGrid.Resources["LineSymbol"] as Symbol;
            _fillSymbol = layoutGrid.Resources["FillSymbol"] as Symbol;

			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];

        // Find map service items with entered information in given fields
        private async void FindButton_Click(object sender, RoutedEventArgs e)
                progress.Visibility = Visibility.Visible;
                resultsGrid.Visibility = Visibility.Collapsed;
                resultsGrid.ItemsSource = null;

                FindTask findTask = new FindTask(
                    new Uri(""));

                var param = new FindParameters()
                    LayerIDs = new List<int> { 0, 1, 2 },
                    SearchFields = new List<string> { "CITY_NAME", "NAME", "SYSTEM", "STATE_ABBR", "STATE_NAME" },
                    ReturnGeometry = true,
                    SpatialReference = MyMapView.SpatialReference,
                    SearchText = txtFind.Text

                var findResults = await findTask.ExecuteAsync(param);
                if (findResults != null && findResults.Results.Count > 0)
                    resultsGrid.ItemsSource = findResults.Results;
                    resultsGrid.Visibility = Visibility.Visible;
            catch (Exception ex)
                MessageBox.Show(ex.Message, "Find Sample");
                progress.Visibility = Visibility.Collapsed;

        // Highlight the selected grid view item on the map
        private void resultsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)

            if (e.AddedItems != null && e.AddedItems.Count > 0)
                var findItem = e.AddedItems.OfType<FindItem>().FirstOrDefault();
                if (findItem != null)
					_graphicsOverlay.Graphics.Add(new Graphic(findItem.Feature.Geometry, ChooseGraphicSymbol(findItem.Feature.Geometry)));

        // Select a marker / line / fill symbol based on geometry type
        private Symbol ChooseGraphicSymbol(Geometry geometry)
            if (geometry == null)
                return null;

            Symbol symbol = null;
            switch (geometry.GeometryType)
                case GeometryType.Point:
                case GeometryType.Multipoint:
                    symbol = _markerSymbol;

                case GeometryType.Polyline:
                    symbol = _lineSymbol;

                case GeometryType.Polygon:
                case GeometryType.Envelope:
                    symbol = _fillSymbol;

            return symbol;
Feedback on this topic?