This sample demonstrates using the ArcGIS Runtime SDK for WPF to perform find operations on local data. To use the sample, specify a search string in the TextBox Control and click the Find Button. Click on rows in the DataGrid at the bottom of the application to see them in the map.
In the code-behind, the sample uses a FindTask to perform the find operation on local data. The task's find parameters specify to search specific layers and fields in the local data.
<UserControlx:Class="ArcGISWPFSDK.LocalFind"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:esri="http://schemas.esri.com/arcgis/client/2009"><Gridx:Name="LayoutRoot"Background="White"><Grid.Resources><BooleanToVisibilityConverterx:Key="BooleanToVisibilityConverter"/><esri:SimpleMarkerSymbolx:Key="DefaultMarkerSymbol"Size="8"Color="Red"Style="Circle"/><esri:SimpleLineSymbolx:Key="DefaultLineSymbol"Color="Red"Width="6"/><esri:SimpleFillSymbolx:Key="DefaultFillSymbol"BorderBrush="Red"BorderThickness="2"Fill="#50FF0000"/><LinearGradientBrushx:Key="PanelGradient"EndPoint="0.5,1"StartPoint="0.5,0"><LinearGradientBrush.RelativeTransform><TransformGroup><ScaleTransformCenterY="0.5"CenterX="0.5"/><SkewTransformCenterY="0.5"CenterX="0.5"/><RotateTransformAngle="176"CenterY="0.5"CenterX="0.5"/><TranslateTransform/></TransformGroup></LinearGradientBrush.RelativeTransform><GradientStopColor="#FF145787"Offset="0.16"/><GradientStopColor="#FF3D7FAC"Offset="0.502"/><GradientStopColor="#FF88C5EF"Offset="0.984"/></LinearGradientBrush></Grid.Resources><Grid.RowDefinitions><RowDefinitionHeight="35"/><RowDefinitionHeight="*"/><RowDefinitionHeight="150"/></Grid.RowDefinitions><StackPanelOrientation="Horizontal"Background="{StaticResource PanelGradient}"HorizontalAlignment="stretch"VerticalAlignment="Top"Height="35"><TextBlockText="Search for"Foreground="White"HorizontalAlignment="Center"Height="24"VerticalAlignment="Center"FontWeight="Bold"FontSize="12"Margin="20,8,5,0"/><TextBoxx:Name="FindText"Background="White"Text="Colorado"Height="23"Width="100"HorizontalContentAlignment="Center"/><TextBlockText="in the attributes of States or Cities:"Foreground="White"HorizontalAlignment="Center"Height="24"VerticalAlignment="Center"FontWeight="Bold"FontSize="12"Margin="5,8,5,0"/><Buttonx:Name="ExecuteButton"Content="Find"Width="75"Height="24"VerticalAlignment="Center"Click="ExecuteButton_Click"IsEnabled="False"Margin="5,0,5,0"Cursor="Hand"/></StackPanel><esri:Mapx:Name="MyMap"MinimumResolution="2445.98490512499"WrapAround="True"Extent="-15000000,2000000,-7000000,8000000"Background="#FFE3E3E3"Grid.Row="1"><esri:ArcGISLocalTiledLayerID="BaseMap"Path="..\\Data\\TPKs\\Topographic.tpk"/><esri:ArcGISLocalDynamicMapServiceLayerPath="..\\Data\\MPKS\\USCitiesStates.mpk"/><esri:GraphicsLayerID="MyGraphicsLayer"/></esri:Map><DataGridx:Name="FindDetailsDataGrid"AutoGenerateColumns="False"HeadersVisibility="All"Background="White"BorderBrush="Black"BorderThickness="1"SelectionChanged="FindDetails_SelectionChanged"HorizontalScrollBarVisibility="Hidden"Grid.Row="2"IsReadOnly="True"HorizontalAlignment="Stretch"VerticalAlignment="Stretch"Height="Auto"Width="Auto"><DataGrid.Columns><DataGridTextColumnBinding="{Binding Path=LayerId}"Header="Layer ID"/><DataGridTextColumnBinding="{Binding Path=LayerName}"Header="Layer Name"/><DataGridTextColumnBinding="{Binding Path=FoundFieldName}"Header="Found Field Name"/><DataGridTextColumnBinding="{Binding Path=Value}"Header="Found Field Value"/></DataGrid.Columns></DataGrid><ProgressBarx:Name="MyProgressBar"IsIndeterminate="True"VerticalAlignment="Bottom"Width="200"Height="20"Margin="10"Visibility="{Binding Path=IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}"></ProgressBar></Grid></UserControl>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Local;
using System.ComponentModel;
namespace ArcGISWPFSDK
{
publicpartialclass LocalFind : UserControl, INotifyPropertyChanged
{
publicevent PropertyChangedEventHandler PropertyChanged;
privatebool _isBusy = true;
publicbool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IsBusy"));
}
}
}
LocalMapService _mapService;
public LocalFind()
{
InitializeComponent();
LocalMapService.GetServiceAsync("..\\Data\\MPKS\\USCitiesStates.mpk", (localMapService) =>
{
_mapService = localMapService;
ExecuteButton.IsEnabled = true;
DataContext = this;
IsBusy = false;
});
}
privatevoid ExecuteButton_Click(object sender, RoutedEventArgs e)
{
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
FindTask findTask = new FindTask();
findTask.Url = _mapService.UrlMapService;
findTask.Failed += FindTask_Failed;
FindParameters findParameters = new FindParameters();
findParameters.LayerIds.AddRange(newint[] { 0, 2 });
findParameters.SearchFields.AddRange(newstring[] { "AREANAME", "CAPITAL", "POP2000", "STATE_NAME" });
Binding resultFeaturesBinding = new Binding("LastResult");
resultFeaturesBinding.Source = findTask;
FindDetailsDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding);
findParameters.SearchText = FindText.Text;
findTask.ExecuteAsync(findParameters);
}
privatevoid FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid dataGrid = sender as DataGrid;
int selectedIndex = dataGrid.SelectedIndex;
if (selectedIndex > -1)
{
FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
Graphic graphic = findResult.Feature;
switch (graphic.Attributes["Shape"].ToString())
{
case"Polygon":
graphic.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
case"Polyline":
graphic.Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
case"Point":
graphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
}
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
graphicsLayer.Graphics.Add(graphic);
}
}
privatevoid FindTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Find failed: " + args.Error);
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Local
Imports System.ComponentModel
Namespace ArcGISWPFSDK
PartialPublicClass LocalFind
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"))
EndSetEndPropertyPrivate _mapService As LocalMapService
PublicSubNew()
InitializeComponent()
LocalMapService.GetServiceAsync("..\Data\MPKS\USCitiesStates.mpk", Function(localMapService__1)
_mapService = localMapService__1
ExecuteButton.IsEnabled = True
DataContext = Me
IsBusy = FalseEndFunction)
EndSubPrivateSub ExecuteButton_Click(sender AsObject, e As RoutedEventArgs)
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
graphicsLayer.ClearGraphics()
Dim findTask AsNew FindTask()
findTask.Url = _mapService.UrlMapService
AddHandler findTask.Failed, AddressOf FindTask_Failed
Dim findParameters AsNew FindParameters()
findParameters.LayerIds.AddRange(NewInteger() {0, 2})
findParameters.SearchFields.AddRange(NewString() {"AREANAME", "CAPITAL", "POP2000", "STATE_NAME"})
Dim resultFeaturesBinding AsNew Binding("LastResult")
resultFeaturesBinding.Source = findTask
FindDetailsDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding)
findParameters.SearchText = FindText.Text
findTask.ExecuteAsync(findParameters)
EndSubPrivateSub FindDetails_SelectionChanged(sender AsObject, e As SelectionChangedEventArgs)
Dim dataGrid As DataGrid = TryCast(sender, DataGrid)
Dim selectedIndex AsInteger = dataGrid.SelectedIndex
If selectedIndex > -1 ThenDim findResult As FindResult = DirectCast(FindDetailsDataGrid.SelectedItem, FindResult)
Dim graphic As Graphic = findResult.Feature
SelectCase graphic.Attributes("Shape").ToString()
Case"Polygon"
graphic.Symbol = TryCast(LayoutRoot.Resources("DefaultFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
ExitSelectCase"Polyline"
graphic.Symbol = TryCast(LayoutRoot.Resources("DefaultLineSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
ExitSelectCase"Point"
graphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
ExitSelectEndSelectDim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
graphicsLayer.ClearGraphics()
graphicsLayer.Graphics.Add(graphic)
EndIfEndSubPrivateSub FindTask_Failed(sender AsObject, args As TaskFailedEventArgs)
MessageBox.Show("Find failed: " & Convert.ToString(args.[Error]))
EndSubEndClassEndNamespace