Query Related Records Online
This sample demonstrates how to use a relationship query to display information from a related table for the selected features. Clicking on the map highlight a set of wells near the clicked point. Select a well from the list to display related features (tops). The object id of the well is used in the relationship query to return 0 or many related records displayed in the data grid.
Note that the code requires a relationshipId. Feature layers can have more than one relationship and each relationship is identified by a unique identifier. You can use the Services Directory to find the relationship id.
Download Sample Application<UserControl x:Class="ArcGISWPFSDK.QueryRelatedRecords" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:esri="http://schemas.esri.com/arcgis/client/2009"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <esri:MarkerSymbol x:Key="SelectMarkerSymbol" OffsetX="7" OffsetY="7"> <esri:MarkerSymbol.ControlTemplate> <ControlTemplate> <Ellipse x:Name="Element" Width="14" Height="14" Fill="Red" Stroke="Black" StrokeThickness="0.5" > <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected" /> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)" To="Cyan" Duration="00:00:0.25"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Ellipse> </ControlTemplate> </esri:MarkerSymbol.ControlTemplate> </esri:MarkerSymbol> <HierarchicalDataTemplate x:Key="TreeViewItemTemplate"> <StackPanel Orientation="Horizontal"> <Ellipse Fill="Transparent" Height="6" Width="6" StrokeThickness="2" Stroke="Black" Margin="0,0,10,0"/> <TextBlock Text="{Binding Attributes[OBJECTID]}" FontWeight="Bold" HorizontalAlignment="Left" FontSize="10" Foreground="Black"/> </StackPanel> </HierarchicalDataTemplate> <LinearGradientBrush x:Key="PanelGradient" EndPoint="0.5,1" StartPoint="0.5,0"> <LinearGradientBrush.RelativeTransform> <TransformGroup> <ScaleTransform CenterY="0.5" CenterX="0.5"/> <SkewTransform CenterY="0.5" CenterX="0.5"/> <RotateTransform Angle="176" CenterY="0.5" CenterX="0.5"/> <TranslateTransform/> </TransformGroup> </LinearGradientBrush.RelativeTransform> <GradientStop Color="#FF145787" Offset="0.16"/> <GradientStop Color="#FF3D7FAC" Offset="0.502"/> <GradientStop Color="#FF88C5EF" Offset="0.984"/> </LinearGradientBrush> </Grid.Resources> <esri:Map x:Name="MyMap" Extent="-10854000,4502000,-10829000,4524000" WrapAround="True" MouseClick="MyMap_MouseClick"> <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" /> <esri:ArcGISDynamicMapServiceLayer ID="DynamicMapWellsLayer" VisibleLayers="0,1" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer" /> <esri:GraphicsLayer ID="GraphicsWellsLayer" /> </esri:Map> <Border x:Name="ResultsDisplay" Background="#77919191" BorderThickness="1" CornerRadius="5" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" Margin="5" Padding="5" BorderBrush="Black"> <Border.Effect> <DropShadowEffect/> </Border.Effect> <Grid x:Name="RelatedRowsGrid" HorizontalAlignment="Right" Background="White" VerticalAlignment="Top" MinHeight="200" Margin="10" MaxWidth="650"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition MaxHeight="170" Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="140" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBlock Text="Wells: " Margin="4,10,10,6" Foreground="Black" TextWrapping="Wrap" FontWeight="Bold" FontSize="10"/> <TreeView x:Name="SelectedWellsTreeView" Grid.Row="1" Grid.Column="0" Margin="2" BorderBrush="Black" BorderThickness="1" ItemsSource="{Binding}" SelectedItemChanged="SelectedWellsTreeView_SelectedItemChanged" ItemTemplate="{StaticResource TreeViewItemTemplate}" /> <TextBlock Margin="4,10,60,6" TextWrapping="Wrap" Grid.Column="1" Foreground="Black" Text="Tops related to the selected well: " FontSize="10" FontWeight="Bold" /> <DataGrid x:Name="RelatedRowsDataGrid" AutoGenerateColumns="False" HeadersVisibility="All" BorderThickness="1" HorizontalScrollBarVisibility="Hidden" Grid.Row="1" Grid.Column="1" IsReadOnly="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="2"> <DataGrid.Columns> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[OBJECTID]}" Header="ID" FontWeight="Bold"/> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[API_NUMBER]}" Header="API Number"/> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[ELEVATION]}" Header="Elevation"/> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[FORMATION]}" Header="Formation"/> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[TOP]}" Header="Top"/> </DataGrid.Columns> </DataGrid> </Grid> </Border> <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0" > <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" > <Rectangle.Effect> <DropShadowEffect/> </Rectangle.Effect> </Rectangle> <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" /> <TextBlock x:Name="InformationTextBlock" Text="Click on map to highlight well points near a location. Select wells in the panel below to view related records." Width="200" Margin="30,20,30,25" HorizontalAlignment="Left" TextWrapping="Wrap" Foreground="Black"/> </Grid> </Grid> </UserControl>
5/16/2014