Select to view content in your preferred language

FeatureDataGrid and GraphicsLayer Binding Issue with Buffer

811
2
Jump to solution
08-01-2013 07:19 AM
TroyProctor
Regular Contributor
So, I've got a buffer setup to select parcels based x number of feet from a point click and then this data binds with a FeatureDataGrid. Everything works fine the first time I select a point but any subsequent clicks on a different point does not show the data in the FeatureDataGrid for some reason.

I'm not sure why the data does not bind the second, third, etc times to BufferResultsQueryDetailsDataGrid when it works fine the first time.

Thanks for any help!
Troy

XAML
<!-- Buffer Results Panel -->         <userControls:WindowPanel x:Name="BufferResultsWindowPanel" Visibility="Collapsed" Width="Auto" Height="Auto"                                    VerticalAlignment="Bottom" HorizontalAlignment="Left"                                        Margin="30,0,0,50">                  <StackPanel>                  <esri:FeatureDataGrid x:Name="BufferResultsQueryDetailsDataGrid" AutoGenerateColumns="False" MaxHeight="150" VerticalScrollBarVisibility="Auto"                         Map="{Binding ElementName=Map}"              GraphicsLayer="{Binding ElementName=Map, Path=Layers.[BufferResultsGraphicsLayer], UpdateSourceTrigger=PropertyChanged}"                                            Style="{StaticResource FeatureDataGridStyle1}">                      <esri:FeatureDataGrid.Columns>                              <data:DataGridTextColumn Binding="{Binding PPN}" Header="PPN" />                             <data:DataGridTextColumn Binding="{Binding OWNERNAME}" Header="Owner Name" />                             <data:DataGridTextColumn Binding="{Binding ADDRESS}" Header="Address" />                          </esri:FeatureDataGrid.Columns>                      </esri:FeatureDataGrid>                                          <Button x:Name="BufferResultsExportAllButton" ToolTipService.ToolTip="Export to Excel" Click="ExportAllButton_Click" HorizontalAlignment="Left"                              Margin="10" Height="25" Width="25">                         <Button.Template>                             <ControlTemplate>                                 <Image Source="/Standard;component/Images/excel2010.png"/>                             </ControlTemplate>                         </Button.Template>                     </Button>                 </StackPanel>              </userControls:WindowPanel>


Code Behind C#
public void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args)         {             _pointAndBufferGraphicsLayer = Map.Layers["BufferGraphicsLayer"] as GraphicsLayer;             _resultsGraphicsLayer = Map.Layers["BufferResultsGraphicsLayer"] as GraphicsLayer;              _pointAndBufferGraphicsLayer.Graphics.Clear();             _resultsGraphicsLayer.Graphics.Clear();              if (IdentifyBorder.Visibility == Visibility.Collapsed)             {                 Map.Cursor = Cursors.Hand;                  //Identify Graphics Object                 GraphicsLayer identifyicongraphicsLayer = Map.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer;                 identifyicongraphicsLayer.Visible = false;                  if (BufferButton.IsChecked == true)                 {                                        //Buffer Tool                     _geometryService =                     new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");                     _geometryService.BufferCompleted += GeometryService_BufferCompleted;                     _geometryService.Failed += GeometryServiceBuffer_Failed;                      _queryTaskBuffer = new QueryTask("http://96.61.212.3/GISServices/rest/services/PFR6-17/MapServer/0");                     _queryTaskBuffer.ExecuteCompleted += QueryTaskBuffer_ExecuteCompleted;                     _queryTaskBuffer.Failed += QueryTaskBuffer_Failed;                      //Buffer Tool                     _geometryService.CancelAsync();                     _queryTask.CancelAsync();                      Graphic clickGraphic = new Graphic();                     clickGraphic.Symbol = LayoutRoot.Resources["BufferMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;                     clickGraphic.Geometry = args.MapPoint;                      // Input spatial reference for buffer operation defined by first feature of input geometry array                     clickGraphic.Geometry.SpatialReference = Map.SpatialReference;                      clickGraphic.SetZIndex(2);                     _pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic);                      // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering                     ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters()                     {                         BufferSpatialReference = new SpatialReference(4326),                         OutSpatialReference = Map.SpatialReference,                         Unit = LinearUnit.Foot,                     };                      //Insert Buffer Radius                     string bufferlength = BufferTextBox.Text;                     double doublebufferlength = Convert.ToDouble(bufferlength);                      bufferParams.Distances.Add(doublebufferlength);                     bufferParams.Features.Add(clickGraphic);                      _geometryService.BufferAsync(bufferParams);                 }                             }  void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args)         {             Graphic bufferGraphic = new Graphic();             bufferGraphic.Geometry = args.Results[0].Geometry;             bufferGraphic.Symbol = LayoutRoot.Resources["BufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;             bufferGraphic.SetZIndex(1);              _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic);                          ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();             query.ReturnGeometry = true;             query.OutSpatialReference = Map.SpatialReference;             query.Geometry = bufferGraphic.Geometry;             query.OutFields.Add("OWNERNAME,PPN,ADDRESS");             _queryTaskBuffer.ExecuteAsync(query);          }          private void QueryTaskBuffer_ExecuteCompleted(object sender, QueryEventArgs args)         {             if (args.FeatureSet.Features.Count < 1)             {                 MessageBox.Show("No features found");                 return;             }              else             {                 if (BufferResultsWindowPanel.IsOpen == false)                 {                     BufferResultsWindowPanel.Toggle();                 }                   foreach (Graphic selectedGraphic in args.FeatureSet.Features)                 {                     selectedGraphic.Symbol = LayoutRoot.Resources["ParcelSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;                     _resultsGraphicsLayer.Graphics.Add(selectedGraphic);                      //Populates the Data Grid with the results and shows the corresponding Window Panel                     BufferResultsQueryDetailsDataGrid.ItemsSource = selectedGraphic.Attributes;                 }                  BufferResultsWindowPanel.Visibility = Visibility.Visible;             }         }          private void GeometryServiceBuffer_Failed(object sender, TaskFailedEventArgs args)         {             MessageBox.Show("Geometry service failed: " + args.Error);         }          private void QueryTaskBuffer_Failed(object sender, TaskFailedEventArgs args)         {             MessageBox.Show("Query failed: " + args.Error);         }         #endregion
0 Kudos
1 Solution

Accepted Solutions
TroyProctor
Regular Contributor
Figured it out.

I guess since I had already done the binding in the XAML for the BufferResultsQueryDetailsDataGrid FeatureDataGrid I did NOT need to set the ItemsSouce in the Code Behind. So after removing this one line of code below each subsequent click works fine now.

//Populates the Data Grid with the results
BufferResultsQueryDetailsDataGrid.ItemsSource = selectedGraphic.Attributes;

View solution in original post

0 Kudos
2 Replies
TroyProctor
Regular Contributor
See Attachements:

First Buffer
[ATTACH=CONFIG]26385[/ATTACH]

Subsequent Buffer
[ATTACH=CONFIG]26386[/ATTACH]
0 Kudos
TroyProctor
Regular Contributor
Figured it out.

I guess since I had already done the binding in the XAML for the BufferResultsQueryDetailsDataGrid FeatureDataGrid I did NOT need to set the ItemsSouce in the Code Behind. So after removing this one line of code below each subsequent click works fine now.

//Populates the Data Grid with the results
BufferResultsQueryDetailsDataGrid.ItemsSource = selectedGraphic.Attributes;
0 Kudos