【发布时间】:2011-05-24 13:51:12
【问题描述】:
我是 WPF 和 Xaml-noob,对于控制台应用程序,我只需提供可执行文件的相对路径即可访问文件。
对我来说,它似乎不适用于 xaml。 (代码在底部)
绝对路径完美运行。
在 WPF 应用程序中的 XAML 中是否可以通过简单地将可执行文件目录的相对路径用作有效的 UriSource 来访问文件?如果是,如何,如果不是,为什么不呢?
我发现了以下问题,他们正在讨论通过 Visual Studio 的“添加现有项目”添加文件,所以这似乎是一个不同的问题。
How can I set the WPF BitmapImage UriSource property to a relative path?
<Window.Icon>
<!--absolute path works:-->
<BitmapImage UriSource="C:\LongPath\SolutionFolder\ProjectFolder\bin\Debug\path4.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>
【问题讨论】:
标签: wpf xaml relative-path