Select to view content in your preferred language

SelectedColor of Graphics Layer

1012
4
06-26-2012 10:49 AM
EdwardSon
Emerging Contributor
This is what I have so far:

<esri:Map x:Name="Map" HorizontalAlignment="Stretch" IsLogoVisible="False"  VerticalAlignment="Stretch"
                      Grid.ColumnSpan="2" Grid.RowSpan="2" WrapAround="True"
                d:DataContext="{Binding Converter={StaticResource SampleGraphicsLayerConverter}, RelativeSource={RelativeSource Self}}">
                <esri:Map.Resources>
                    <esri:FillSymbol x:Key="SelectFillSymbol">
                        <esri:FillSymbol.ControlTemplate>
                            <ControlTemplate>
                                <Path x:Name="Element"
       Stroke="Black"
       StrokeStartLineCap="Round"
       StrokeThickness="2"
       StrokeLineJoin="Round"
       StrokeEndLineCap="Round"
       Fill="Blue">
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="SelectionStates">
                                            <VisualState x:Name="Unselected" >
                                                <Storyboard>
                                                    <ColorAnimation Storyboard.TargetName="Element"
           Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)"
           To="Blue"  Duration="00:00:00.25"/>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Selected">
                                                <Storyboard>
                                                    <ColorAnimation Storyboard.TargetName="Element"
           Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)"
           To="Yellow" Duration="00:00:00.25"/>
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Element" Storyboard.TargetProperty="StrokeDashArray">
                                                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <DoubleCollection>2,1</DoubleCollection>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                </Path>
                            </ControlTemplate>
                        </esri:FillSymbol.ControlTemplate>
                    </esri:FillSymbol>
                </esri:Map.Resources>
            </esri:Map>

and

foreach (Graphic graphic in featureSet.Features)
            {
                graphic.Symbol = MapApplication.Current.Map.Resources["SelectFillSymbol"] as Symbol;
                graphicsLayer.Graphics.Add(graphic);
            }

where featureSet is the result of a query.

Everything goes fine and when I run the application I can see that the graphic flashes Blue initially, indicating it takes the applied style for the symbol.
But then it resets itself to what it was before the templated custom symbol is applied.

Why does it reset?
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
But then it resets itself to what it was before the templated custom symbol is applied.


What do you mean by 'then'? Is it due to a user action or to the execution of another code?

I don't understand either what you mean by 'what it was before the templated custom symbol is applied' ? Your graphics seem directly created with your custom symbol.
0 Kudos
EdwardSon
Emerging Contributor
Thanks for your reply.

I am using the silverlight viewer application template and configured the map using the app builder.
In it I have a feature layer which comes with a default symbology, with outline, fill color, and selection color.
In the builder, I have control over the outline color and fill color, but not the selection color.

I do a query against this feature layer to return the graphics which I use to build a graphicslayer.
The symbology seems to be based on the feature layer symbology.

I can override the selection color the "feature" layer in the code using the SelectedColor property.
For the graphicslayer I used the above procedure, but it seems to reset itself to what it was before I apply the templated symbology.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
For the graphicslayer I used the above procedure, but it seems to reset itself to what it was before I apply the templated symbology.

Are you adding the features in a graphicsLayer that is in fact a FeatureLayer?  That might explain why features coming from the server and features added by code are mixed.


If your graphicsLayer is just a simple graphicslayer with features added by code, I still don't get what you mean by 'it seems to reset itself to what it was before I apply the templated symbology'. A graphicsLayer don't know anything about the symbology defined at server side so the only symbology that can be used by a graphicslayer is the symbology that you defined by code or XAML.
0 Kudos
EdwardSon
Emerging Contributor
Apparently had to set graphicsLayer.RendererTakesPrecedence = false;
0 Kudos