Flashing a graphic in the ESRI Silverlight API
Being able to flash a shape on the map is a nice usability feature in GIS applications to relate shapes on the map to attributes in a data table or data grid. Also, most GIS users have gotten used to the feature in ArcMAP. I had written up an extension method to the Graphic class in the ESRI Silverlight API to be able to do this easily with a simple function call. Here is the code for the extension method.
public static void Flash( this Graphic graphic )
{
Flash( graphic, 200, 10 );
}
public static void Flash( this Graphic graphic, double milliseconds, int repeat )
{
int count = 1;
repeat = repeat * 2;
Symbol tempSymbol = graphic.Symbol;
Storyboard storyboard = new Storyboard();
storyboard.Duration = TimeSpan.FromMilliseconds( milliseconds );
graphic.Symbol = null;
storyboard.Completed += ( sender, e ) =>
{
if( count % 2 == 1 )
graphic.Symbol = tempSymbol;
else
graphic.Symbol = null;
if( count <= repeat )
storyboard.Begin();
count++;
};
storyboard.Begin();
}
After including the above extension method in your project just call the ‘Flash’ method on the graphic object
graphic.Flash();
Note that I am using the Storyboard as the timer which is preferred over of the DispatcherTimer.
This has also been added to the ESRI Silverlight API Contrib project here.
Wow.. nice tips.. I’m really need this.. thank u
Thanks Nice code! it works fine…
Having trouble converting this to VB. Can anyone help?
Thank you for providing this code. However, I don’t see a flash when I call this method. I stuck a MessageBox(“working”) at the beginning of the Flash method in your code and confirmed that it is actually being called as expected, but nothing happened with the feature (no flash). Would you have any clues why I might not be seeing anything?