I'm, a WPF & Xaml-noob, for console applications it has worked for me to simply give the relative path to the executable to access a file.
It doesn't seem to work in xaml for me. (code at the bottom)
Absolute path works perfectly.
Is it possible in XAML in a WPF-application to access a file by simply using a relative path to the directory of your executable as a valid UriSource? If yes how and if not why not?
I found the following question, where they were talking about adding the file via Visual Studio's "Add existing item", so it seems like a different issue.
How can I set the WPF BitmapImage UriSource property to a relative path?
<Window.Icon>
<!--absolute path works:-->
<BitmapImage UriSource="C:LongPathSolutionFolderProjectFolderinDebugpath4.ico" />
<!--none of the following relative paths worked:-->
<!--AppDomain.CurrentDomain.BaseDirectory returns the Debug-folder-->
<!--<BitmapImage UriSource="path4.ico" />-->
<!--<BitmapImage UriSource="../path4.ico" />-->
<!--<BitmapImage UriSource="Debug/path4.ico" />-->
<!--<BitmapImage UriSource="bin/Debug/path4.ico" />-->
<!--<BitmapImage UriSource="../bin/Debug/path4.ico" />-->
<!--<BitmapImage UriSource="../../bin/Debug/path4.ico" />-->
<!--<BitmapImage UriSource="../Debug/path4.ico" />-->
</Window.Icon>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…