Setting Image.Source doesn't update when loading from a resource.
Posted
by ChrisF
on Stack Overflow
See other posts from Stack Overflow
or by ChrisF
Published on 2010-05-29T23:44:07Z
Indexed on
2010/05/29
23:52 UTC
Read the original article
Hit count: 199
I've got this definition in my XAML:
<Image Name="AlbumArt" Source="/AlbumChooser2;component/Resources/help.png" />
The image is display OK on startup.
In my code I'm looking for mp3's to play and I display the associated album art in this Image
. Now if there's no associated image I want to display a "no image" image. So I've got one defined and I load it using:
BitmapImage noImage = new BitmapImage(
new Uri("/AlbumChooser2;component/Resources/no_image.png",
UriKind.Relative));
I've got a helper class that finds the image if there is one (returning it as a BitmapImage
), or returns null if there isn't one:
if (findImage.Image != null)
{
this.AlbumArt.Source = findImage.Image; // This works
}
else
{
this.AlbumArt.Source = noImage; // This doesn't work
}
In the case where an image is found the source is updated and the album art gets displayed. In the case where an image isn't found I don't get anything displayed - just a blank.
I don't think that it's the setting of AlbumArt.Source
that's wrong, but the loading of the BitmapImage
.
If I use a different image it works, but if I recreate the image it doesn't work. What could be wrong with the image?
© Stack Overflow or respective owner