Reputation: 5497
The code below works in another project. Also in the second one if I include absolute url. I have the res folder in my project folder. What can be different?
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"\res\arato.png", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
var img = new Image();
img.Source = myBitmapImage;
img.Margin = new Thickness(0, 0, 0, 0);
canvas.Children.Add(img);
Upvotes: 1
Views: 431
Reputation: 5234
This likely has to do with the build action on the file. If you view the properties on the file inside of Visual Studio you should see Build Action. Wpf plays best with "Resource" and doesn't work as well with "Embedded Resource". Sadly, Embedded Resource has the more intuitive name (at least to me), so I had trouble with this when i was first learning WPF.
Upvotes: 0
Reputation: 5497
The solution was: I had to drag the pictures to the folder in Visual Studio, not in File Explorer.
Upvotes: 0