Dynamic Feature DataForm FeatureLayer

741
2
02-04-2011 10:20 AM
DonFreeman
New Contributor
I have a FeatureDataForm coded like this.
<esri2:FeatureDataForm x:Name="MyFeatureDataForm"   
       FeatureLayer="{Binding Path=Layers[AllAvailableFeatureLayer], ElementName=MyMap}" 
       IsEnabled="True"
                            IsReadOnly="False" 
       LabelPosition="Left"
       />

And code behind like this.
 private void AllAvailableFeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
   {
   FeatureLayer featureLayer = sender as FeatureLayer;

   for (int i = 0; i < featureLayer.SelectionCount; i++)
    featureLayer.SelectedGraphics.ToList().UnSelect();

   args.Graphic.Select();
   MyFeatureDataForm.GraphicSource = args.Graphic;

   FeatureDataFormBorder.Visibility = Visibility.Visible;
   MyPopup.IsOpen=true;
   }


I would like to make the FeatureLayer in the DataForm dynamic so that it is set to the layer which triggered the mouse click. Would this be possible and what would be the syntax?
Thanks
0 Kudos
2 Replies
AliMirzabeigi
New Contributor
I think the easiest way would be having the same MouseLeftButtonUp event handler for all your feature layers and setting FeatureDataForm's FeatureLayer and GraphicSource properties based upon the values of the sender object and the GraphicMouseButtonEventArgs argument in your handler, i.e. in your XAML:
<esri2:FeatureDataForm x:Name="MyFeatureDataForm" ........... />

And in your code-behind:
private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
{
 FeatureLayer featureLayer = sender as FeatureLayer;
 for (int i = 0; i < featureLayer.SelectionCount; i++)
  featureLayer.SelectedGraphics.ToList().UnSelect();
 args.Graphic.Select();
 
 MyFeatureDataForm.FeatureLayer = featureLayer;
 MyFeatureDataForm.GraphicSource = args.Graphic;
 FeatureDataFormBorder.Visibility = Visibility.Visible;
 MyPopup.IsOpen=true;
}
0 Kudos
DonFreeman
New Contributor
I think the easiest way would be having the same MouseLeftButtonUp event handler for all your feature layers and setting FeatureDataForm's FeatureLayer and GraphicSource properties based upon the values of the sender object and the GraphicMouseButtonEventArgs argument in your handler, i.e. in your XAML:
<esri2:FeatureDataForm x:Name="MyFeatureDataForm" ........... />

And in your code-behind:
private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
{
 FeatureLayer featureLayer = sender as FeatureLayer;
 for (int i = 0; i < featureLayer.SelectionCount; i++)
  featureLayer.SelectedGraphics.ToList().UnSelect();
 args.Graphic.Select();
 
 MyFeatureDataForm.FeatureLayer = featureLayer;
 MyFeatureDataForm.GraphicSource = args.Graphic;
 FeatureDataFormBorder.Visibility = Visibility.Visible;
 MyPopup.IsOpen=true;
}


Great! Just one line was needed. I never thought it could be that easy.
Thanks
0 Kudos