Jeff
Jeff

Reputation: 36563

WPF Resource URI

I feel like I've solved this problem 10 times before but I can never remember how exactly to do it, since someone decided to make pack uris in xaml complete rocket science..

I have an image marked as a resource. I have a xaml UserControl in a class library (a dll) that needs to reference this image in markup. I have this UserControl and image in two dlls - a Silverlight version and a WPF version.

The image is in the same directory as the UserControl in both versions. It's marked as "Resource"

I have a Silverlight app that references the Silverlight dll and a WPF app that references the WPF dll.

How can I make my xaml reference the image with an assembly local relative URI, keeping in mind the following:

  1. I don't know the assembly name, since the SL and WPF assemblies have different names.
  2. The Silverlight and WPF dlls have different paths relative to the root of the assembly (the SL version of the UserControl and image are linked files under a directory named "Linked" in the SL project.

I've tried using

./MyImage.png
MyImage.png
/MyImage.png (which I know shouldn't work)

Upvotes: 0

Views: 397

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

Just "MyImage.png" should work if both it and the control are in project root folder. If both are under Controls - you would need "Controls/MyImage.png". The path isn't relative to control location - it is relative to project root folder.

Upvotes: 0

Related Questions