ImageBrush ImageSource doesn't support paths relative to TextureProvider Root
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?
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?
-
-
sfernandez
Site Admin
- Posts: 3198
- Joined:
Re: ImageBrush ImageSource doesn't support paths relative to TextureProvider Root
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:
This behavior is the same for both Image or ImageBrush, as both use the same ImageSourceConverter.
So the following paths should work:
Code: Select all
<ImageBrush ImageSource="/Textures/Image.png"/>
<ImageBrush ImageSource="/MyAssembly;component/Textures/Image.png"/>
<ImageBrush ImageSource="pack://application:,,,/Textures/Image.png"/>
Re: ImageBrush ImageSource doesn't support paths relative to TextureProvider Root
Ohh wow no idea how I missed the leading slash there!
Thank you and merry christmas :)
Thank you and merry christmas :)
Who is online
Users browsing this forum: No registered users and 1 guest