MainWindow.xaml:

<Window x:Class="MyApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Images.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <Button x:Name="RecStartButton" Content="Button" HorizontalAlignment="Left" Margin="209,43,0,0" VerticalAlignment="Top" Width="129" Height="67" Click="RecStart"/> <ListBox x:Name="FindedSong" HorizontalAlignment="Left" Height="100" Margin="172,174,0,0" VerticalAlignment="Top" Width="312"/> <Image x:Name="FindedSongPicture" HorizontalAlignment="Left" Height="100" Margin="45,174,0,0" VerticalAlignment="Top" Width="100"/> </Grid> </Window> 

enter image description here

Images.xaml:

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ImageSource x:Key="NoAlbum">Resources/NoAlbum.png</ImageSource> </ResourceDictionary> 

I insert a picture in Image:

 FindedSongPicture.Source = (ImageSource)FindResource("NoAlbum"); 

I receive:

enter image description here

What is the problem?

  • Everything works for me (c). Maybe you incorrectly inserted the picture? What is your build action for it? - VladD
  • At first there wasn’t, then I installed Resource, in both cases it doesn’t work - zaki hatfild
  • Recheck, maybe you incorrectly specified the path to the resource? I get the same error message if I make a typo along the way. - VladD
  • Maybe somewhere Russian letter instead of English? - VladD
  • one
    Okay, try this: <BitmapImage x:Key="NoAlbum" UriSource="Resources/NoAlbum.png"/> . So in 2013 I took off. - VladD

1 answer 1

In Visual Studio 2015, such code as in question works great.

For Visual Studio 2013, you need to give a little hint to the framework:

 <BitmapImage x:Key="NoAlbum" UriSource="Resources/NoAlbum.png"/>