开发者

How to get the height of an Image in Silverlight?

I have this code in Silverlight:

Image image = new Image();
BitmapImage bitmapImage= TheDatasourceManager.GetBitmapImage("blackPencil");
image.Source = bitmapImage;
image.Stretch = Stretch.None;
image.HorizontalAlignment = HorizontalAlignment.Left;
image.VerticalAlignment = VerticalAlignment.Top;
image.Margin = new Thickness(88, 88, 0, 0);
grid.Children.Add(image);

Now I want to find out the height of the image.

  • in WPF I can get it with image.Source.Height but this is not available in Silverlight
  • bitmapImage.Height doesn't exist either
  • when I debug and 开发者_如何转开发examine the image object, I eventually get to PixelHeight which has an accurate height, but I can't seem to access it
  • I find image.ActualHeight but it is 0.

How can I get the height of the image?


I finally found it, it's just bitmapImage.PixelHeight. Since I'm not stretching it, seems to work fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜