Condividi tramite


ImageOpened

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the image source for an Image or ImageBrush is downloaded and decoded with no failure.

<object ImageOpened="eventhandlerFunction"  .../>
[token = ]object.AddEventListener("ImageOpened", eventhandlerFunction)

Arguments

AddEventListener Parameters

token

integer

A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token.

eventhandlerFunction

object

The name of your event handler function as it is defined in JavaScript. When used as an AddEventListener parameter, quotation marks around the function name are not required. (For more information, see the "Remarks" section.)

Event Handler Parameters

sender

object

The object that invoked the event.

eventArgs

object

This parameter is always set to null.

Remarks

In the managed API, you can use the PixelWidth and PixelHeight properties on the ImageSource to determine the image characteristics before rendering it. In the JavaScript API, you can use this technique, but you must explicitly declare a BitmapImage object in the XAML markup, so that there is an object available that reports PixelWidth and PixelHeight. Otherwise, the image source is interpreted as a URI and does not create an intermediate object that you can use in JavaScript. The following is an example of the markup:

<Image>
  <Image.Source>
    <BitmapImage ImageOpened="imgOpened" UriSource="cocointhesnow.png"/>
  </Image.Source> 
</Image>

For the imgOpened handler (not shown), the sender is a BitmapImage, and the PixelHeight and PixelWidth properties are available.

You can also attach an ImageOpened handler for either Image or ImageBrush. However, this is considerably less useful for obtaining a pre-rendered image dimension because PixelHeight and PixelWidth are not available properties without the explicit BitmapImage.

Version Information

Silverlight 3