0

作成したグリッドに画像が表示されない理由がわかりません

Image img = new Image();

img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Relative));

img.Width = 50;
img.Height = 50;
img.Margin = new Thickness(5, 5, 5, 5);

grid1.Children.Add(img);
4

1 に答える 1

3

画像 URI は絶対パスです。

あなたは書くべきです

img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Absolute));

またはそれ以上

img.Source = new BitmapImage(new Uri(@"C:\logo.bmp"));
于 2013-02-27T16:14:29.067 に答える