Frapie
Frapie

Reputation: 225

Why doesn't my image display in the grid?

I can't find the reason why the image won't display in the grid I created

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);

Upvotes: 0

Views: 91

Answers (1)

Clemens
Clemens

Reputation: 128013

Your image URI is an absolute path.

You should write

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

or better

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

Upvotes: 3

Related Questions