Select to view content in your preferred language

How to change TextSymbol color when its Graphic is selected?

765
2
10-25-2010 05:26 PM
ChenLi
by
Emerging Contributor
I tried to follow the sample Graphics/Selections (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics) to make a TextSymbol, but the Graphic will show nothing with this TextSymbol. Please help:


<esri:TextSymbol x:Name="DefaultTextSymbol">
    <esri:TextSymbol.ControlTemplate>
        <ControlTemplate>
            <TextBlock x:Name="Element" FontFamily="Arial" FontSize="16" Foreground="Red" Text="ABC">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="SelectionStates">
                        <VisualState x:Name="Normal">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="Element"
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                    To="Red" Duration="00:00:00.25"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Selected">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="Element"
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                    To="Cyan" Duration="00:00:00.25"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </TextBlock>
        </ControlTemplate>
    </esri:TextSymbol.ControlTemplate>
</esri:TextSymbol>

TextSymbol textSymbol = DefaultTextSymbol;
textSymbol.Text = "xyz;
graphic.Symbol = textSymbol;
MyGraphicsLayer.Graphics.Add(graphic);
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
One issue is that you didn't bind the Textblock to Symbol.Text:
 
<TextBlock x:Name="Element" FontFamily="Arial" FontSize="16" Foreground="Red"  Text="{Binding Symbol.Text}">


That being said, it doesn't fully explain your issue because you shoud get a fixed string : "ABC".

Perhaps an issue with the geometry of your graphic. How did you initialize it?
0 Kudos
ChenLi
by
Emerging Contributor
After the machine reboot, the above XAML works. Don't know why.
Thank you, Dominique, the text graphic is added to a graphicLayer by Draw.DrawMode = DrawMode.Point.
Chen Li
0 Kudos