Select to view content in your preferred language

Use existing symbol in custom template

900
2
03-14-2013 10:15 AM
dmacq
by
Occasional Contributor
I have an application that dynamically creates a feature layer if the corresponding layer in a dynamic service is made visible.

I understand how to create a custom control template and set the fill, etc.  However, what I'd like to do is inherit the feature layer's existing symbology, then modify specific aspects of it.

For example, I have a yellow polygon with a red boundary.  When moused over, I'd like the red boundary to expand in thickness, and I'd like for the opacity of the yellow fill to "darken".  As I have many feature layers, I'd rather not hand-create a renderer for each one. 

Should I be looking at the code-behind, instead?  I didn't think it was possible to modify the default control template.
0 Kudos
2 Replies
JohanCarlsson
Regular Contributor
Have you tried getting the renderer for the layer you are working with?
http://resources.arcgis.com/en/help/silverlight-api/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Gra...

I have never done this but I would begin with examining this possibility.
0 Kudos
dmacq
by
Occasional Contributor
Thanks for the suggestion, Johan.  I started to go that route, but things got a bit convoluted.

I ended up creating Control Templates for each potential symbol type, then I apply the control template to the existing symbol.

I created the control templates in a resource dictionary:
<ControlTemplate x:Key="FeatureFill">
        <Path x:Name="Element" Fill="{Binding Symbol.Fill}" Stroke="{Binding Symbol.BorderBrush}" StrokeThickness="{Binding Symbol.BorderThickness}" Opacity="0.10">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" >
                        <Storyboard>                            
                            <DoubleAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Symbol.Opacity)" To="{Binding Symbol.Opacity}" Duration="00:00:00" />
                            <DoubleAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Path.StrokeThickness)" To="{Binding Symbol.BorderThickness}" Duration="00:00:00.5" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="MouseOver">
                        <Storyboard>                            
                            <DoubleAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Symbol.Opacity)" To="1" Duration="00:00:00" />
                            <DoubleAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Path.StrokeThickness)" To="3" Duration="00:00:00.2" />
                        </Storyboard>
                    </VisualState>
                   
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </Path>
    </ControlTemplate>


Then I apply the template in an UpdateCompleted event handler:
 resDict = new ResourceDictionary() { Source = new Uri("/IViewer;component/Styles/FeatureLayerStyle.xaml", UriKind.Relative) };
 ControlTemplate ct = resDict["FeatureFill"] as ControlTemplate;

            foreach (Graphic g in fLayer.Graphics)
            {
                g.Symbol.ControlTemplate = ct;
            }
0 Kudos