0

I want to access some file outside the current project (wpfg as below). But I cannot use ../ to navigate further up than root.

The file structure is like this:

  • UI
    • wpfg
      • app.xaml
      • screen
        • history.xaml
    • textures
      • background.png

I want to use background.png in history.xaml. I tried

<Image Source="../../textures/background.png" />

but it won't work.

Note that I'm not able to move the textures folder or associate it with the project. Also I cannot write C# code. More context: How to access an image that doesn't belong to any project/assembly with relative path

  • 1
    Be aware that the file structure at runtime (when you access the file) has not much to do with the file structure of your Visual Studio project or solution. The application may be deployed somewhere, while the textures folder could reside anywhere else. You need a means to tell the application where the textures folder really is, i.e. a configuration parameter. Or consider moving the folder to a well known location, e.g. Environment.SpecialFolder.ApplicationData. – Clemens Mar 26 '21 at 06:58
  • Does this answer your question? [Wpf - relative image source path](https://stackoverflow.com/questions/1444699/wpf-relative-image-source-path) – Rekshino Mar 26 '21 at 07:40
  • Try the solution with value converter. – Rekshino Mar 26 '21 at 07:41
  • @Rekshino Thanks but I cannot use that solution. I'm modding a game and only XAML code is exposed to me, no C# code accessible. More context here: https://stackoverflow.com/q/66783557/5616592 – Yuren Huang Mar 26 '21 at 12:05
  • @Clemens Thanks! Could you explain more about the "configuration parameter"? Would be nice if there is an example. Also I did state that I cannot move the folder. It is a game installed from Steam. – Yuren Huang Mar 26 '21 at 12:09
  • I don't now whether it is applicable for your case, but may be simlink files can help, if you put them to the project folder. – Rekshino Mar 26 '21 at 12:33
  • @Rekshino Nice to know about symbolic link. But symlink files are not recognized as game files so I cannot pack them into a mod. I can only edit XAML code. – Yuren Huang Mar 26 '21 at 13:47

0 Answers0