Question

I have tried every way I can find to make my custom control understand URI packs - both in generic.xaml and code. All examples I find works fine in my user controls, but never in custom controls.

All files are set to Resource - except for generic.xaml, if I change that the custom control stops displaying all together.

If I try any kind of pack URI I get errors at compile time. Relative or absolute, doesn't matter. I've tried putting the images in other assemblies as well, but with no luck.

If I try New Uri("/Images/btnImage.PNG", UriKind.Relative) it looks for C:\Images\btnImage.PNG, which is wrong. I've also tried Images/btnImage.PNG or ./Images/btnImage.PNG but then it looks for C:\MyProject\bin\Debug\Images\btnImage.PNG.

The only thing I get to work is an absolutely absolute URI - i.e. New Uri("C:/MyProject/Images/btnImage.PNG", UriKind.Absolute).

  1. Do custom controls only understand file system absolute URI's?
  2. If 1 = No Then Return correctAnswer (please)
Was it helpful?

Solution

I ended up using pack URIs, but not without hitting a few snags along the way.

Most examples don't bother to mention you can't use the "short version" pack URIs to refer to the current assemply if the projects a class library.

OTHER TIPS

If you write /Images/btnImage.PNG that means go back to the root and walk into the directory Images.

What you mean should be ether ./Images/btnImage.PNG or Images/btnImage.PNG which means look from this dir in the subdirectory Images.

UPDATE The problem seems to be your actual working directory. Your program is executed in C:\MyProject\bin\Debug so the relativ path points correctly to C:\MyProject\bin\Debug\Images\btnImage.PNG. Try to change the working directory while debugging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top