Add image using Source
property of the Image
control by clicking
then the path will be something like this:
/[project name];component/[folder name: e.g. Images]/[file name]
Pregunta
In a legacy project there are absolute path to the images, for example:
C:/projects/LegacyProject/Project/Client/UserInterface/Images/arrow.png
Now I want to use relative path, so that every developer can use that project, no matter where he has his copy of the sourcecode.
Is there an easy way to find out the (Resource) relative path? How can I use it then?
At the moment I have for example:
<Image Source="C:/projects/LegacyProject/Project/Client/UserInterface/Images/arrow.png" Stretch="Fill" />
What I want is something like:
<Image Source="arrow.png" Stretch="Fill" />
Tried around with
<Image Source="pack:,,, arrow.png" Stretch="Fill" />
<Image Source="/WPF1;arrow.png"></Image>
and similar things
Solución 2
Add image using Source
property of the Image
control by clicking
then the path will be something like this:
/[project name];component/[folder name: e.g. Images]/[file name]
Otros consejos
Put the image files into a folder (named let's say Images
) in your Visual Studio project and set their build action to Resource
.
Now you can simply use them in XAML like this:
<Image Source="Images/arrow.png" ... />
In code-behind you would have to write
var uri = new Uri("pack://application:,,,/Images/arrow.png");
image.Source = new BitmapImage(uri);