<!-- RELATED LINK RESOURCE-->
<common:HierarchicalDataTemplate x:Key="TreeViewItemTemplate">
<StackPanel Orientation="Horizontal" Margin="0">
<!--<Ellipse Fill="Transparent" Height="6" Width="6" StrokeThickness="2" Stroke="Black" Margin="0,0,10,0"/>-->
<TextBlock Text="APN: " HorizontalAlignment="Left" FontSize="10" Margin="0"/>
<TextBlock x:Name="TextBlockRelate" Text="{Binding Attributes[APN], Mode=TwoWay}" HorizontalAlignment="Left" FontSize="10"/>
</StackPanel>
</common:HierarchicalDataTemplate>
<!--END RELATED LINK RESOURCE-->
<userControls:DraggableWindow x:Name="RelateResultsDisplay" IsOpen="False"
VerticalAlignment="Bottom" HorizontalAlignment="Right"
Margin="15" Effect="{StaticResource dropShadow}" Title="RELATED WORK RESULTS TABLE" Background="Black">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" >
<Border Effect="{StaticResource miniDropShadow}" Style="{StaticResource RibbonElementBorder}" Padding="15" Margin="10">
<Grid x:Name="RelatedRowsGrid" HorizontalAlignment="Right"
VerticalAlignment="Top" MinHeight="170" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140" />
<ColumnDefinition MaxWidth="600" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Margin="1,-5,1,5">
<TextBlock Margin="1,0,5,1" TextWrapping="Wrap" Grid.Column="0"
Text="Click to see relates: "
FontSize="10" FontFamily="Arial" Foreground="#FFFFFFFF" />
<basics:TreeView x:Name="SelectedWellsTreeView" MaxHeight="180" Grid.Column="0" Margin="1"
ItemsSource="{Binding}" BorderBrush="Gray" BorderThickness=".5"
SelectedItemChanged="SelectedWellsTreeView_SelectedItemChanged"
ItemTemplate="{StaticResource TreeViewItemTemplate}"
/>
</StackPanel>
<esriWidgets:FeatureDataGrid Grid.Column="1" Grid.Row="1" x:Name="MyFDG" Height="180"
Style="{StaticResource FeatureDataGridRelateStyle1}" MouseLeftButtonUp="MyFDG_MouseLeftButtonUp"
/>
</Grid>
</Border>
</Grid>
</userControls:DraggableWindow>
<userControls:DraggableWindow x:Name="ResultsDisplay" IsOpen="True"
VerticalAlignment="Bottom" HorizontalAlignment="Right"
Margin="15" Effect="{StaticResource dropShadow}" Title="RESULTS TABLE" Background="Black">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" >
<Border Effect="{StaticResource miniDropShadow}" Style="{StaticResource RibbonElementBorder}" Padding="15" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock x:Name="DataDisplayTitle" Text="Search Results" FontSize="9" Grid.Row="0" FontWeight="Bold" FontFamily="Arial" Foreground="#FFFFFFFF" />
<esriWidgets:FeatureDataGrid Grid.Row="1" x:Name="QueryDetailsDataGrid" Height="170"
Map="{Binding ElementName=Map}"
GraphicsLayer="{Binding Layers[MySelectionGraphicsLayer], ElementName=Map}" Style="{StaticResource FeatureDataGridStyle1}" MouseLeftButtonUp="QueryDetailsDataGrid_MouseLeftButtonUp" SelectionChanged="QueryDetailsDataGrid_SelectionChanged"
/>
</Grid>
</Border>
</Grid>
</userControls:DraggableWindow>
private void SelectedWellsTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.OldValue != null)
{
Graphic g = e.OldValue as Graphic;
g.UnSelect();
g.SetZIndex(0);
}
if (e.NewValue != null)
{
Graphic g = e.NewValue as Graphic;
g.Select();
g.SetZIndex(1);
//OBJECTID, PARCELID, X_COORD, Y_COORD, APN, ADDRNMBR, ADDRNAME, GEN_PLAN
//Relationship query
RelationshipParameter relationshipParameters = new RelationshipParameter()
{
ObjectIds = new int[] { Convert.ToInt32(g.Attributes[SelectedWellsTreeView.Tag as string]) },
OutFields = new string[] { "*" },
RelationshipId = 0,
OutSpatialReference = Map.SpatialReference,
};
queryTask.ExecuteRelationshipQueryAsync(relationshipParameters);
relateIDstring = g.Attributes["APN"].ToString();
// MessageBox.Show(g.Attributes["OWN_ADDR1"].ToString());
// MyFeatureDataForm.GraphicSource = g;
}
}
void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
{
// This line gets you the all features returned from the Relationship Query
// IEnumerable<Graphic> graphics = e.Result.RelatedRecordsGroup.First().Value;
RelationshipResult pr = e.Result;
if (pr.RelatedRecordsGroup.Count == 0)
{
l.Where = "1=0"; //remember _featureLayer is l
// RelatedRowsDataGrid.ItemsSource = null;
}
else
{
foreach (var pair in pr.RelatedRecordsGroup)
{
IEnumerable<Graphic> graphics = e.Result.RelatedRecordsGroup.First().Value;
// RelatedRowsDataGrid.ItemsSource = pair.Value;
// MyFDG.ItemsSource = pair.Value;
// MyFDG.ItemsSource = pair.Value.Select(graphic => graphic.Attributes);
// }
//}
// There are two ways to filter either using Where clause or using the ObjectIDs property
// before you set the Where clause to return all records 1=1 I think
// Here instead lets use the ObjectIDs approach, first get rid of the old Where
l.Where = null; //remember _featureLayer is l
//ObjectIDs takes an int[] and with a little Linq we can get that array
// I am assumning you have included OBJECTID in your outfields when you defined the query
int[] objectIds = graphics.Select(g => (int)g.Attributes["OBJECTID_1"]).ToArray();
//now set the ObjectIDs on our FeatureLayer
l.ObjectIDs = objectIds;
}
}
//Update the FeatureLayer to 'redraw' the new filtered set of Features
l.Update();
//And I hope this worked. you could rebind the layer to the grid to make sure all is good
MyFDG.GraphicsLayer = l;
MyFeatureDataForm.FeatureLayer = l;
// MyFDG.Resources["SeeRelateButton"].Visibility = Visibility.Visible;
}
#endregionSolved! Go to Solution.
private void GraphicsLayer_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedGraphics" && ResultsDisplay.IsOpen == true && QueryDetailsDataGrid.SelectedGraphics.Count == 1) { GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; var objectidi = QueryDetailsDataGrid.SelectedGraphics.First().Attributes["OBJECTID_1"]; strObjecitID = objectidi.ToString(); intObjectID = Int32.Parse(strObjecitID); MessageBox.Show(strObjecitID); RelationshipParameter relationshipParameters = new RelationshipParameter() { Convert.ToInt32(QueryDetailsDataGrid.SelectedGraphics.First().Attributes["OBJECTID"] as string) }, ObjectIds = new int[] { intObjectID }, OutFields = new string[] { "*" }, RelationshipId = 0, OutSpatialReference = Map.SpatialReference, }; queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); relateIDstring = apn10; } } private void GraphicsLayer_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedGraphics" && ResultsDisplay.IsOpen == true && QueryDetailsDataGrid.SelectedGraphics.Count == 1) { GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; var objectidi = QueryDetailsDataGrid.SelectedGraphics.First().Attributes["OBJECTID_1"]; strObjecitID = objectidi.ToString(); intObjectID = Int32.Parse(strObjecitID); MessageBox.Show(strObjecitID); RelationshipParameter relationshipParameters = new RelationshipParameter() { Convert.ToInt32(QueryDetailsDataGrid.SelectedGraphics.First().Attributes["OBJECTID"] as string) }, ObjectIds = new int[] { intObjectID }, OutFields = new string[] { "*" }, RelationshipId = 0, OutSpatialReference = Map.SpatialReference, }; queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); relateIDstring = apn10; } }