【问题标题】:Absolute UriSource of a Resource image资源图像的绝对 UriSource
【发布时间】:2010-12-24 03:47:35
【问题描述】:

我有一个 WPF 项目。如果我将图像存储在 {ProjectRoot}\Images\image.png 中,并将其编译为资源,那么我可以通过 BitmapImage UriSource="Images/image.png" 从 xaml(此 xaml 位于根)作为 BitmapImage 访问它。但是如果我将 xaml 移动到另一个文件夹,比如 {ProjectRoot}\Xamls,现在我必须使用 BitmapImage UriSource="../Images/image.png"。有没有办法指定一个绝对的项目路径,这样无论xaml的位置如何,我都可以用相同的路径引用它们?

【问题讨论】:

    标签: .net wpf xaml uri


    【解决方案1】:

    您可以使用此语法在同一个项目中通过绝对路径引用,或在其他项目中引用文件:

    UriSource="/MyAssemblyName;component/Images/image.png"
    

    这里“MyAssemblyName”是项目/dll/exe名称,“component”表示项目根目录。

    【讨论】:

    • component indicates the project root 是什么意思?是要代替component,还是应该使用实际单词?无法使其正常工作。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2010-09-06
      • 1970-01-01
      • 2019-10-18
      • 2017-11-05
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多