How to Change MarkerSymbol Color at runtime

689
3
07-19-2012 10:18 PM
TubaKumbara
Occasional Contributor
My code is below and i want to change GradientStop  colors and static ellipse (X:name="ellipse1") control color at runtime.
With below code, the color is red and seems good. But i want to change runtime with some color code. Such as blue etc.

Inadvance thanks.

 <esri:MarkerSymbol x:Key="StrobeMarkerSymbol">
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Canvas>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard RepeatBehavior="ForEver">

                                            <DoubleAnimation BeginTime="0"
                 Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
                 From="1" To="10" Duration="00:00:01" />

                                            <DoubleAnimation BeginTime="0"
                 Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
                 From="1" To="10" Duration="00:00:01" />

                                            <DoubleAnimation BeginTime="0"
                 Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"
                 From="1" To="0" Duration="00:00:01" />
                                        </Storyboard>
                                    </VisualState>
                                    <!--If normal state is not specified, the animation will 
              keep going until a mouse out. Keep it empty to transition back to original symbol. -->
                                    <VisualState x:Name="Normal" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <!--Strobe ellipse-->
                            <!--Note that IsHitTestVisible="False" on the strobe symbol,
        so only the static ellipse will trigger mouse over/mouse out-->
                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" 
           RenderTransformOrigin="0.5,0.5" x:Name="ellipse"
           IsHitTestVisible="False"
           >
                                <Ellipse.RenderTransform>
                                    <ScaleTransform />
                                </Ellipse.RenderTransform>
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="#00FF0000" />
                                        <GradientStop Color="#FFFF0000" Offset="0.25"/>
                                        <GradientStop Color="#00FF0000" Offset="0.5"/>
                                        <GradientStop Color="#FFFF0000" Offset="0.75"/>
                                        <GradientStop Color="#00FF0000" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <!--Static symbol on top-->
                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" 
           Fill="#FFFF0000" x:Name="ellipse1"/>
                        </Canvas>
                    </ControlTemplate>
                </esri:MarkerSymbol.ControlTemplate>
            </esri:MarkerSymbol>


0 Kudos
3 Replies
JoeHershman
MVP Regular Contributor
The  most straightforward way would be to define another symbol in XAML (with different key) that is what you want.  Then in code simply change the symbol of the graphic to this new symbol at the place you want in code



    existing_graphic.Symbol = LayoutRoot.Resources["NewStrobeMarkerSymbol"] as Symbol

Thanks,
-Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
This thread should help.
0 Kudos
TubaKumbara
Occasional Contributor
This thread should help.


thanks. this is what i want 🙂
0 Kudos