private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args) { args.Graphic.Selected = !args.Graphic.Selected; if (args.Graphic.Selected) MyDataGrid.ScrollIntoView(args.Graphic, null); }
<esri:FeatureLayer ID="California" Renderer="{StaticResource SelectRenderer}" Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer/8" OutFields="*" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown" /> ... <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[California]}" />The map user click actually is a feature layer and the featureDataGrid is binding to a GraphicsLayer (the same feature layer anyway). I make some changes from the sample for my application. If I get rid of the feature layer and the GraphicsLayer is returned from a query and I worte a similar GraphicsLayer_MouseLeftButton Down function, if you click the map, the entry in the FeatureDataGrid can be highlighted, but when I click a row in the FeatureDataGrid, the feature on the map doesn't highlight. What do I miss here?private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e) { e.Graphic.Selected = !e.Graphic.Selected; if (e.Graphic.Selected) MyDataGrid.ScrollIntoView(e.Graphic, null); }
The XAML from my code:<esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown" /> .... <esri:FeatureDataGrid x:Name="MyDataGrid" Background="White" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayer]}" > </esri:FeatureDataGrid>
Solved! Go to Solution.
No idea.
Can you share a piece of code allowing to reproduce the issue?
<Grid.Resources> <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" /> <esri:SimpleMarkerSymbol x:Key="MyMarkerSymbol" Color="Blue"/> </Grid.Resources> <esri:Map x:Name="MyMap" WrapAround="true" Background="White" Extent="-130, 20, -65, 55"> <!--"{StaticResource BaseColor}" >--> <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" /> <esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown"> <esri:GraphicsLayer.MapTip> <Border esri:GraphicsLayer.MapTipHideDelay="00:00:0.5" BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15" > <Border.Effect> <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" /> </Border.Effect> <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="4" BorderBrush="#77FF0000" Name="MapTipBorder"> <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10"> <StackPanel> <HyperlinkButton TargetName="_blank" Content="{Binding Path=[Organization_Name]}" HorizontalAlignment="Center" Foreground="RED" NavigateUri="{Binding [Link]}" /> </StackPanel> </StackPanel> </Border> </Border> </esri:GraphicsLayer.MapTip> </esri:GraphicsLayer> </esri:Map> <esri:FeatureDataGrid x:Name="MyDataGrid" Background="White" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayer]}" > </esri:FeatureDataGrid>
public partial class MainPage : UserControl { private string strUrl = null; private QueryTask queryTask; public MainPage() { InitializeComponent(); MyMap.Layers.LayersInitialized += Layers_LayersInitialized; } void Layers_LayersInitialized(object sender, EventArgs args) { bool? flag = PPP_States.IsChecked; if (!flag.HasValue) { flag = false; } if ((bool)flag) { strUrl = "http://130.70.253.91/ArcGIS/rest/services/PPP/PP/MapServer/5"; ExcuteQuery(strUrl); } } private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { FeatureSet featureSet = args.FeatureSet; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); if (featureSet != null && featureSet.Features.Count > 0) { foreach (Graphic feature in featureSet.Features) { if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon) { feature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; } else { feature.Symbol = LayoutRoot.Resources["MyMarkerSymbol"] as Symbol; } graphicsLayer.Graphics.Add(feature); } } } // Notify when query fails. private void QueryTask_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("Query failed: " + args.Error); } private void ExcuteQuery(string Url) { ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query(); query.Geometry = MyMap.Extent; query.ReturnGeometry = true; query.OutFields.Add("*"); if (Url != null) { queryTask = new QueryTask(strUrl); } else { queryTask = new QueryTask("http://130.70.3.72/ArcGIS/rest/services/STATES/MapServer"); } queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; queryTask.ExecuteAsync(query); } private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args) { args.Graphic.Selected = !args.Graphic.Selected; if (args.Graphic.Selected) MyDataGrid.ScrollIntoView(args.Graphic, null); } private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args) { args.Graphic.Selected = !args.Graphic.Selected; if (args.Graphic.Selected) MyDataGrid.ScrollIntoView(args.Graphic, null); } }
I think I got your issue.
It's not tied to your feature datagrid. Your selection by mouse click is not working either.
I think it's related to your symbol that is not managing the 'Selected' state. So your feature is selected but there is no visual effect.
You can either create your own custom symbol or use the feature service symbol.
In your XAML, add this line: xmlns:symbols="clr-namespace:ESRI.ArcGIS.Client.FeatureService.Symbols;assembly=ESRI.ArcGIS.Client"
and define your fill symbol this way:
<symbols:SimpleFillSymbol x:Key="DefaultFillSymbol" SelectionColor="Cyan" />
That should do the trick.