Select to view content in your preferred language

featuredatagrid and binding with graphicslayers & featurelayers

1276
17
08-11-2010 09:19 AM
MichaelBlom
Deactivated User
Hi there,

I'm creating a featuredatagrid that I want to link with my map (select grid, map graphic selected and vice versa a la this example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid)

but I need my featuredatagrid to reference a GraphicsLayer, not a FeatureLayer

...I create my GraphicsLayer in the xaml:
<esri:GraphicsLayer ID="StormRegions"/>

...do the binding in the xaml:
<esri:FeatureDataGrid Grid.Row="2" x:Name="stormsDataGrid" Visibility="Visible"
    Map="{Binding ElementName=RiskMap}"
                GraphicsLayer="{Binding ElementName=RiskMap, Path=Layers.[StormRegions]}"

...and then reference in my code behind:
stormPolys = RiskMap.Layers["StormRegions"] as GraphicsLayer;

...and then populate the GraphicsLayer:
stormPolys.Graphics.Insert(0, feature);

The problem is, in binding a GraphicsLayer, I don't seem to get the same kind of map-datagrid-selection-interaction that binding a FeatureLayer to a FeatureDataGrid seems to acheive.

Has anyone managed to achieve this someone?

Thanks in Advance,
Mike
0 Kudos
17 Replies
JenniferNery
Esri Regular Contributor
The Binding looks correct and it should work.

Do your Graphics include Attributes? The Attributes will define the field names for the FeatureDataGrid. Do you show the rows and columns?

What does your FeatureDataGrid display on GraphicsLayer MouseLeftButtonDown?

Jennifer
0 Kudos
MichaelBlom
Deactivated User
Hi Jennifer,

Thank-you for your reply.

My Graphics do include attributes (including shape) and the Binding is working between the GraphicsLayer and the FeatureDataGrid, all the attributes are displayed.

My Graphics don't show on my Map though.

MouseLeftDown on the grid does nothing, but this might be because I can't see the graphics on my map (am I right to say that clicking on the datagrid row should inherently select the graphic on the map without adding any code behind?)

Thanks,
Mike
0 Kudos
AliMirzabeigi
Emerging Contributor
If you cannot see your graphics on the map then it seems that you haven't defined the "Symbol" property of your GraphicsLayer.
0 Kudos
JenniferNery
Esri Regular Contributor
Yup. Ali is right, no graphics can be clicked because there's no symbol for it. You can set GraphicsLayer.Renderer in XAML. It shouldn't be any different than how FeatureLayer.Renderer is set so you can refer to these sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerRendering You can simply use SimpleRenderer with the appropriate symbol template for your geometry type.

Jennifer
0 Kudos
MichaelBlom
Deactivated User
Thank you both.

I don't actually need to set breaks, define bins and all that stuff that goes with renderers.

I'd like to just apply a simplefillsymbol to my graphicslayer.  A transparent one actually, so that all i see is the blue "selected" border when i click on the record in my datagrid.  The layer is already "on" the map via a dynamic map service.

Is it the case that I must define a renderer in order to display a graphics layer?

It looks like a featurelayer you can just apply a simplefillsymbol, but not a graphicslayer.

Thanks again,
Mike

oh, i also tried in code behind, but graphicslayer is still not showing on my map.

SimpleFillSymbol fillSymbol = new SimpleFillSymbol()
                {
                    BorderBrush = new SolidColorBrush(Color.FromArgb(0, 255, 0, 0)),
                    BorderThickness = 2,
                    Fill = new SolidColorBrush(Color.FromArgb(0, 255, 0, 0))
                };

foreach (var f in stormPolys.Graphics)
                    f.Symbol = fillSymbol;
stormPolys.Refresh();
0 Kudos
MichaelBlom
Deactivated User
Ok, I've found this.

"A set of new symbol renderers are available for graphics and feature layers:
SimpleRenderer - Used to define a single symbol to render features in a graphics or feature layer. Enables the ability to define a single symbol in XAML with which to render graphics in a graphic layer. While this was possible for feature layer using the FeatureSymbol property, this provides a single standard pattern for all graphics layers and derivatives.
"

Perfect, exactly what i'm looking for:
<Grid.Resources>
         <esriSymbols:SimpleFillSymbol x:Key="ClearFill" Fill="#66FF0000" BorderBrush="Red" BorderThickness="2"/>
            <esri:SimpleRenderer x:Key="MySimpleRenderer" Symbol="{StaticResource ClearFill}">
            </esri:SimpleRenderer>
        </Grid.Resources>
....
<esri:GraphicsLayer ID="StormRegions" Renderer="{StaticResource MySimpleRenderer}" Visible="True" />
...


But my graphics still are not showing up on my map... I'm going crazy.

I've also tried to apply the renderer in the code behind:

stormPolys.Renderer = MySimpleRenderer; 


Nothing....
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Might be a geometry type issue.

FillSymbols are working with polygon geometry.
What is the geometry type of your graphics? How do you initialize it?
0 Kudos
AliMirzabeigi
Emerging Contributor
Mike,

For GraphicsLayer you need to either define a Renderer to be used by all features in your layer or set the Symbol property of each layer while adding them to your layer. To use the first approach (Renderer with a transparent symbology in which gets a blue border when the graphic element gets selected) you can use the following resource in your XAML:
            <esri:SimpleFillSymbol x:Key="TransparentFillSymbol">
                <esri:SimpleFillSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Path x:Name="Element" Fill="Transparent" Stroke="Transparent" StrokeThickness="1">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                            Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)" 
                                                            To="Transparent" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                            Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)" 
                                                            To="Blue" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Path>
                    </ControlTemplate>
                </esri:SimpleFillSymbol.ControlTemplate>
            </esri:SimpleFillSymbol>


Then define a Renderer like the following code snippet:

<esri:SimpleRenderer x:Key="TransparentRenderer" Symbol="{StaticResource TransparentFillSymbol}" />
And finally, define your GraphicsLayer like below in your map layers collection:

<esri:GraphicsLayer ID="MyGraphicsLayer" Renderer="{StaticResource TransparentRenderer}" />


Doing this way you won't need to set the symbol property of each graphic object while adding them into your GraphicsLayer.
0 Kudos
MichaelBlom
Deactivated User
Thanks for your code Ali, its very elegant... but it doesn't seem to work in my case here.

I got to looking at the features I add into my GraphicsLayer, these features are the results of a querytask where my query does include ReturnGeometry = true.

foreach (var feature in stormPolygons.FeatureSet.Features)
            {
                foreach(var att in feature.Attributes)
                {
                    string keyvalue = att.Key.ToString();
                }


I itterated through the attributes, and I have a Shape_Length attribute, and a Shape_Area attribute, but no traditional seen SHAPE attribute. 

Could this be an issue?
0 Kudos