I've read that too, but naming the assembly explicitly is the only working way. I am reading books about WPF now and it helps me to understand the designers' twists of thought, but still I struggle with the complexity. But when I have created an interactive, working dialog, I am happy. WPF is something you can both love and hate at the same time.
For my applications I always use a custom Image control. This is the class:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace GenericSystem.WPF
{
public class AppImage : Image
{
private string m_AppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
private string m_LocalSource = string.Empty;
/// <summary>
/// Get or set the local source file. It is returned to the Source Property as correct Uri.
/// </summary>
/// <value>Path from root and filename (/Resources/image.jpg): result is 'pack://application:,,,/[Applicationname];component/[LocalSource]'</value>
public string LocalSource
{
get { return this.m_LocalSource; }
set
{
if (string.IsNullOrWhiteSpace(value) == false)
{
m_LocalSource = value.Trim().TrimStart('/');
base.Source = new BitmapImage(new Uri($"pack://application:,,,/{m_AppName};component/{m_LocalSource}", UriKind.RelativeOrAbsolute));
}
}
}
/// <summary>
/// Reroute the property Source.
/// </summary>
public new Uri Source
{
get { throw new Exception("Use LocalSource instead Source!"); }
set { throw new Exception("Use LocalSource instead Source!"); }
}
}
}
In the XAML you need a reference:
xmlns:i="clr-namespace:GenericSystem.WPF"
And then you only need to use this to show an image:
<i:AppImage LocalSource="/Resources/myImage.jpg" />
And because it is still an Image object, you can also use all the attributes like Width and Height.
It makes it much more easy to use images and this is also a perfect way to reuse the XAML in other assemblies as well, because you don't hardcode the assembly name in the XAML.