Click here to Skip to main content
15,797,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have .PNG files in the debug folder that I use as imagebrushes and diffusematerials with no issue. I.E.:
myImageBrush.ImageSource = New BitmapImage(New Uri("image0.png", UriKind.Relative))

Now I have two Image controls and I set the source I.E.:
myImage.Source = New BitmapImage(New Uri("image0.png", UriKind.Relative))

Nothing appears.

What I have tried:

Unless I set a breakpoint, inspect the Image in debug AND expand the source section and scroll to the bottom and then continue. If I do that, the image displays - I don't have to do anything else.

SO I have .PNG files that work fine - except on Image controls. If I expand the Image details in debug mode, I have no issue, otherwise the Image simply doesn't display.

Any idea what is going on?
Updated 8-Sep-23 10:52am
Richard MacCutchan 8-Sep-23 5:33am    
Where is the code that actually paints the image?
kamikazehighland 8-Sep-23 8:09am    
Private myImage As New Image

Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
myImage.Margin = New Thickness(12, 12, 0, 0)
myImage.HorizontalAlignment = HorizontalAlignment.Left
myImage.Width = 100
myImage.Source = New BitmapImage(New Uri("image0.png", UriKind.Relative))
End Sub
Richard MacCutchan 8-Sep-23 10:20am    
Take a look at How to: Use the Image Element - WPF .NET Framework | Microsoft Learn[^], it shows how you should set imager properties.
Gerry Schmitz 8-Sep-23 11:16am    
Add an "ImageFailed" event handler. Since you're doing "relative" addressing, it probable couldn't find the image "relative" to the image control.
kamikazehighland 8-Sep-23 12:54pm    
It's odd that "New BitmapImage(New Uri("image0.png", UriKind.Relative))" works well for Imagebrushes but not Images. I put the full path with UriKind.Absolute and it works with no issue. And especially odd that when I pause and view the Source info that makes it work all of a sudden.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900