Click here to Skip to main content
15,443,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to use the SharpVectors package in my project.

This is my XAML.

I get an exception when I run my app: {"Cannot locate resource 'resources/image.svg'."}

This works if I replace the source path with an url.

https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/rg1024_green_grapes.svg[^]


Question : the "Resources/image.svg" is relative to where ?

Here's an image of my folder structure :

paths - Album on Imgur[^]


<Window x:Class="TestLayout.MainWindow"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:local="clr-namespace:TestLayout"
                 xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
                 mc:Ignorable="d"
                 Title="TestLayout" Height="450" Width="800">


	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="50" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>

		<StackPanel Grid.Row="1" Orientation="Vertical">
			<Button Margin="10">
				<svgc:SvgViewbox Height="20" Width="20" Source="Resources/image.svg"/>
			</Button>
		</StackPanel>
    </Grid>
</Window>


What I have tried:

I've tried setting the source to :
"/Resources/image.svg"
"../Resources/image.svg"
Posted
Updated 2-Jul-21 3:31am
Comments
Gerry Schmitz 3-Jul-21 1:51am     CRLF
In my case, I used "/Images/xxx.png" and set my file's "Build Action" to "Content". (Using "Content" since it proved "smoother" than retrieving embedded images for my scenario)

1 solution

For WPF, relative URIs are references to resources embedded within the current application:
By default, a relative pack URI is considered relative to the location of the markup or code that contains the reference.
 
Share this answer
 
Comments
Maximilien 5-Jul-21 8:24am    
Thanks Richard, I also needed to change the "Build Action" of the resources in project settings for the file.
TheRealSteveJudge 9-Jul-21 6:34am    
Why only 4*? This answer is worth 5*.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900