Vishful thinking…

Flashing a graphic in the ESRI Silverlight API

Posted in ESRI, Silverlight by viswaug on May 28, 2009

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.

4 Responses

Subscribe to comments with RSS.

  1. Joddie said, on May 28, 2009 at 5:17 am

    Wow.. nice tips.. I’m really need this.. thank u

  2. Vipul Soni said, on December 14, 2010 at 6:29 am

    Thanks Nice code! it works fine…

  3. Paul said, on June 7, 2011 at 8:49 pm

    Having trouble converting this to VB. Can anyone help?

  4. Terry said, on August 11, 2011 at 7:40 pm

    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?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: