Query Related Records
This sample demonstrates using the ArcGIS Runtime SDK for WPF to perform a relationship query to display information from a related table for selected features. Click on the map to highlight a State. Select a State from the list to display related features (cities). The object id of the State 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. Local feature layers can have more than one relationship and each relationship is identified by a unique identifier.
Download Sample Application<UserControl x:Class="ArcGISWPFSDK.LocalQueryRelatedRecords" 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> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <esri:FillSymbol x:Key="SelectFillSymbol"> <esri:FillSymbol.ControlTemplate> <ControlTemplate> <Path x:Name="Element" Stroke="Black" StrokeStartLineCap="Round" StrokeThickness="2" StrokeLineJoin="Round" StrokeEndLineCap="Round" Fill="Red"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected" > <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Path.Fill).Color" To="Red" Duration="00:00:00.25"/> </Storyboard> </VisualState> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Path.Fill).Color" To="Cyan" Duration="00:00:00.25"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Element" Storyboard.TargetProperty="StrokeDashArray"> <DiscreteObjectKeyFrame KeyTime="0:0:0"> <DiscreteObjectKeyFrame.Value> <DoubleCollection>2,1</DoubleCollection> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Path> </ControlTemplate> </esri:FillSymbol.ControlTemplate> </esri:FillSymbol> <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[STATE_NAME]}" 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> <esri:SimpleRenderer x:Key="MySimplePolygonRenderer"> <esri:SimpleRenderer.Symbol> <esri:SimpleFillSymbol Fill="#440000FF"/> </esri:SimpleRenderer.Symbol> </esri:SimpleRenderer> </Grid.Resources> <esri:Map x:Name="MyMap" Extent="-15000000,2000000,-7000000,8000000" Background="#FFE3E3E3" MinimumResolution="2445.98490512499" MouseClick="MyMap_MouseClick" IsEnabled="False"> <esri:ArcGISLocalTiledLayer ID="BaseMap" Path="..\\Data\\TPKs\\Topographic.tpk"/> <esri:ArcGISLocalFeatureLayer ID="States" LayerName="States" Path="..\\Data\\MPKs\\RelationshipID.mpk" Renderer="{StaticResource MySimplePolygonRenderer}"/> <esri:GraphicsLayer ID="GraphicsStatesLayer" /> </esri:Map> <Border x:Name="ResultsDisplay" Background="{StaticResource PanelGradient}" 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="120" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBlock Text="States: " Margin="4,10,10,6" Foreground="Black" TextWrapping="Wrap" FontWeight="Bold" FontSize="10"/> <TreeView x:Name="SelectedStatesTreeView" Grid.Row="1" Grid.Column="0" Margin="2" BorderBrush="Black" BorderThickness="1" ItemsSource="{Binding}" SelectedItemChanged="SelectedStatesTreeView_SelectedItemChanged" ItemTemplate="{StaticResource TreeViewItemTemplate}" /> <TextBlock Margin="4,10,60,6" TextWrapping="Wrap" Grid.Column="1" Foreground="Black" Text="Cities related to the selected State: " 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[NAME]}" Header="City Name"/> <DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[POP2000]}" Header="Population"/> </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 State. Select State in the panel below to view related records." Width="200" Margin="30,20,30,25" HorizontalAlignment="Left" TextWrapping="Wrap" Foreground="Black"/> </Grid> <ProgressBar x:Name="MyProgressBar" IsIndeterminate="True" VerticalAlignment="Bottom" Width="200" Height="20" Margin="10" Visibility="{Binding Path=IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}"></ProgressBar> </Grid> </UserControl>
5/16/2014