Sunday, August 2, 2009

New features in Silverlight 3: Bitmap API & AddHandler

Taking snapshot of playing video …  Handling already-handled route event …. Silverlight 3 has many new features, hasn’t it?  Read my post about these two features.

Bitmap API

One of the new features in Silverlight 3 is the Bitmap API which provides the ability to render UIElements to a bitmap and provides direct access to the pixel level information of bitmaps. It is useful for taking snapshots of playing video, generating fractals, and for data visualization. The key to generating a bitmap is the WriteableBitmap class. Note that it does not render popup controls, such as Popup, ToolTip and ComboBox.

WriteableBitmap

Routed Events: AddHandler

The API AddHandler provides a technique whereby you can attach a handler that will always be invoked for the route, even if some other handler earlier in the route has set Handled to true. This technique is useful if a control you are using has handled the event in its internal compositing or for control-specific logic but you still want to respond to it on a control instance, or higher in the route.

In order to use AddHandler, the routed event must expose a public static field that is the event identifier, which is required for the routedEvent parameter. This is only true for a limited set of events in the Silverlight core classes: KeyDown; KeyUp; MouseLeftButtonDown; MouseLeftButtonUp. Do not use Loaded event and AddHandler; Loaded is not a true routed event in the Silverlight implementation. MouseMove cannot be used with AddHandler because there is no Handled in its event data. BindingValidationError cannot be used with AddHandler because there is no event identifier, and also because there is no control handling of the event.

AddHandler

No comments: