Wuceng
Topic Author
Posts: 10
Joined: 04 Aug 2024, 16:43

ImageBrush ImageSource doesn't support paths relative to TextureProvider Root

18 Dec 2024, 22:11

In my project I have an image in a folder with the path "Content/Textures/Image.png"
I have a TextureProvider which has it's root set to the "Content" folder.
When I use an image element like this it can find the given texture for the image and everything works as expected:
<Image Source="/Textures/Image.png"/> -> Works
However if I use an ImageBrush like this it does not resolve the path relative the the TextureProvider root, instead I can only use a path relative to the xaml with the brush inside.
<ImageBrush ImageSource="Textures/Image.png"/> -> Can't find image
<ImageBrush ImageSource="../../Textures/Image.png"/> -> Can find image
Is there a specific reason the ImageBrush behaves different here, and is there something I can do to make it work with paths relative to my TextureProvider root?
 
User avatar
sfernandez
Site Admin
Posts: 3198
Joined: 22 Dec 2011, 19:20

Re: ImageBrush ImageSource doesn't support paths relative to TextureProvider Root

18 Dec 2024, 23:52

Uri paths are relative to the XAML file where they are defined unless you start with '/' or use the full assembly ("/MyAssembly;component/path/to/img.png") or pack ("pack://application:,,,/path/to/image.png") versions.

So the following paths should work:
<ImageBrush ImageSource="/Textures/Image.png"/>
<ImageBrush ImageSource="/MyAssembly;component/Textures/Image.png"/>
<ImageBrush ImageSource="pack://application:,,,/Textures/Image.png"/>
This behavior is the same for both Image or ImageBrush, as both use the same ImageSourceConverter.
 
Wuceng
Topic Author
Posts: 10
Joined: 04 Aug 2024, 16:43

Re: ImageBrush ImageSource doesn't support paths relative to TextureProvider Root

20 Dec 2024, 20:55

Ohh wow no idea how I missed the leading slash there!
Thank you and merry christmas :)
 
User avatar
jsantos
Site Admin
Posts: 4215
Joined: 20 Jan 2012, 17:18
Contact:

Re: ImageBrush ImageSource doesn't support paths relative to TextureProvider Root

20 Dec 2024, 21:02

Thank you!

Who is online

Users browsing this forum: No registered users and 1 guest