How to resize images in Silverlight 4?
Doing something like 开发者_开发百科this doesn't work.
foreach (Image img in Canvas1.Children.OfType<Image>())
{
double h = img.Height / 2;
double w = img.Width / 2;
img.Height = h;
img.Width = w;
img.UpdateLayout();
Canvas1.UpdateLayout();
}
Must I transform the BitmapImage which I assign to the Image with some kind of Transform-class or something like that?
I just tested changing the size of images and it worked for me:
foreach (var item in _grid.Children.OfType<Image>())
{
item.Width = 400; // Update calls are unnecessary
}
One thing that might be wrong with your code is that you access Image.Height
/Width
without setting it first. If those properties are not set they are on Auto
(which is Double.NaN
), if you want to retrieve the current values which are calculated by the layout system use ActualHeight
/Width
.
精彩评论