2
// Create the image element.
Image simpleImage = new Image();    
simpleImage.Width = 100;
simpleImage.Margin = new Thickness(5);

// Create source.
BitmapImage bi = new BitmapImage();

我应该如何将 simpleImage 的 Source 设置为 bi?

4

2 回答 2

2
// Create the image element.
Image simpleImage = new Image();    
simpleImage.Width = 200;
simpleImage.Margin = new Thickness(5);

// Create source.
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri(@"/Images/1.jpg",UriKind.RelativeOrAbsolute);

bi.EndInit();
// Set the image source.
simpleImage.Source = bi;
于 2013-10-09T08:52:54.060 回答
2
var uri = new Uri(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg");
var bi = new BitmapImage(uri);
simpleImage.Source = bi;
于 2013-10-09T09:02:27.207 回答