Programming - Silvelight 2 - Working out dimensions of a dynamically loaded image
Silverlight is an excellent platform, but lacks the ability to inspect a dynamically loaded image's size until rendered. So here is a snippet to do just that.
Uri path = new Uri(“YOUR URL”, UriKind.Absolute);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = path;
bitmapImage.DownloadProgress +=
new EventHandler<DownloadProgressEventArgs>(bitmapImage_DownloadProgress);
yourImage = new Image();
yourImage.Source = bitmapImage;
void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{ if (e.Progress == 100)
{ Dispatcher.BeginInvoke(delegate()
{ GetSizes();
});
}
}
void GetSizes (){ double height = yourImage.ActualHeight;
double width = yourImage.ActualWidth;
}