The CompositionTarget.Rendering event is a plain old EventHandler, with a plain old EventArgs. However, in real life, it apparently always gets an instance of RenderingEventArgs. So your event handler has to start by casting the EventArgs in order to get the useful information out of them.
Why isn't the event of type EventHandler<RenderingEventArgs>
, so we could get to the arguments more easily (and more importantly, so we could even know the arguments are there)? Why would Microsoft have chosen to give this event the wrong signature?
I wondered about backward compatibility -- was there a release where RenderingEventArgs didn't exist yet? -- but that doesn't seem to be the case. According to MSDN, RenderingEventArgs and CompositionTarget were introduced in the same release on both platforms -- in WPF, both were added in .NET 3.0; in Silverlight, both were added in Silverlight 3.0.
If it gives any kind of hint, I ran across an old discussion thread where somebody said, "The delegate is using EventArgs because there's some kind of performance win on marshalling by doing that." If someone can explain what kind of performance win that might be, I'd be willing to accept that as an answer.