Image.Source setting does not update when loading from resource

I have this definition in my XAML:

<Image Name="AlbumArt" Source="/AlbumChooser2;component/Resources/help.png" />

The image starts at startup. Ok

In my code, I am looking for mp3s to play, and I am showing the associated album art in this Image. Now, if there is no linked image, I want to display the "no image" image. So, I have one specific one, and I load it using:

BitmapImage noImage = new BitmapImage(
              new Uri("/AlbumChooser2;component/Resources/no_image.png",
                      UriKind.Relative));

I have a helper class that finds an image if it is (returns it as BitmapImage), or returns null if it is not:

if (findImage.Image != null)
{
    this.AlbumArt.Source = findImage.Image; // This works
}
else
{
    this.AlbumArt.Source = noImage; // This doesn't work
}

In the event that an image is found, the source is updated and the album art is displayed. In the case when the image is not found, I do not see anything - just a space.

, AlbumArt.Source , BitmapImage.

, (, ), " ", . ?

+3
2

/:

Visual Studio no_image.png? " " ""? " " " "?

, , ? , , "" " ".

, UriKind UriKind.Absolute ?

noImage , Source, /?

+3

Bitmapimge Wpf?

wpf .exe , .exe u can not access,

BitmapImage noImage = new BitmapImage(
          new Uri("/AlbumChooser2;component/Resources/no_image.png",
                  UriKind.Relative))

Resources.no_image.png BitmapImage.

REV

0

Source: https://habr.com/ru/post/1747707/


All Articles