2

I have a WPF project. If I store image in {ProjectRoot}\Images\image.png, and compile it as Resource then I can access it from a xaml (this xaml is located at Root) as BitmapImage by BitmapImage UriSource="Images/image.png". But if I move the xaml to another folder, say {ProjectRoot}\Xamls, now I have to use BitmapImage UriSource="../Images/image.png". Is there a way to specify an absolute project path, so that I can refer to them with the same path regardless of the location of the xaml?

Louis Rhys
  • 34,517
  • 56
  • 153
  • 221

2 Answers2

3

Take a look at Pack URIs in WPF

biju
  • 17,554
  • 10
  • 59
  • 95
3

You can use this syntax both to reference by an absolute path inside the same project, or reference files in other projects:

UriSource="/MyAssemblyName;component/Images/image.png"

Here "MyAssemblyName" is the project/dll/exe name and "component" indicates the project root.

John Bowen
  • 24,213
  • 4
  • 58
  • 56
  • What do you mean by `component indicates the project root`? Is something meant to be put in place of `component`, or should the actual word be used? Not able to get this working. – Philip Guin Apr 13 '16 at 20:46