相关疑难解决方法(0)

Xaml - Bitmap UriSource - 绝对路径工作,相对路径没有,为什么?

我是一个WPF和Xaml-noob,对于控制台应用程序,它对我来说只是给出了可执行文件的相对路径来访问文件.它对我来说似乎不适用于xaml.(底部代码)
绝对路径完美无缺.

是否可以在WPF应用程序的XAML中通过简单地使用可执行文件目录的相对路径作为有效的UriSource来访问文件?如果是的话,如果不是,为什么不呢?

我发现了以下问题,他们在谈论通过Visual Studio的"添加现有项目"添加文件,所以这似乎是一个不同的问题.

如何将WPF BitmapImage UriSource属性设置为相对路径?

<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>
Run Code Online (Sandbox Code Playgroud)

wpf xaml relative-path

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

relative-path ×1

wpf ×1

xaml ×1