I added an image in my Visual Studio project and I am trying to access it in my XAML resource dictionary without specifying the complete path to where it is on my hard drive.
<ImageBrush x:Key="image" ImageSource="Cherries.jpg"></ImageBrush>
I added an image in my Visual Studio project and I am trying to access it in my XAML resource dictionary without specifying the complete path to where it is on my hard drive.
<ImageBrush x:Key="image" ImageSource="Cherries.jpg"></ImageBrush>
You could use a pack URI.
Make sure that the Build Action
of the image is set to its default value of Resource
.
You can specify a path like this where you replace "Subfolder" with the name of the folder within your project where the image resource resides:
<ImageBrush x:Key="image" ImageSource="pack://application:,,,/Subfolder/Cherries.jpg" />
If you have put the image in the root folder the path would be:
<ImageBrush x:Key="image" ImageSource="pack://application:,,,/Cherries.jpg" />
If it is located in another assembly, you inlcude the name of this one:
<ImageBrush x:Key="image" ImageSource="pack://application:,,,/ReferencedAssembly;component/Cherries.jpg" />