none
Should a shared event interrogate sender or args.OriginalSource? RRS feed

  • Question

  • With this code (any number of dynamically created Pushpins on a Bing map are all hooked to this event), is the first "as" line preferable or the second?

        private void PushPin_OnTapped(object sender, TappedRoutedEventArgs args)
        {
            //Pushpin pushpin = sender as Pushpin;
            Pushpin pushpin = args.OriginalSource as Pushpin;
            if (pushpin is Pushpin)
            {
               
            }
        }

    Note: In agreement with Petzold's way of doing things, I always change the "e" to "args" in event handlers.

    Wednesday, November 28, 2012 8:43 PM

Answers

  • It doesn't really matter. If you want to be really safe wrap your code with an if statement and use the "is" parameter to check if the object is a Pushpin first.

    http://rbrundritt.wordpress.com

    Tuesday, December 4, 2012 10:00 AM