关于 .net:资源图像的绝对 UriSource | 珊瑚贝

Absolute UriSource of a Resource image


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


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

1
UriSource=”/MyAssemblyName;component/Images/image.png”

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

  • component indicates the project root 是什么意思?是要代替 component 的东西,还是应该使用实际的词?无法使其正常工作。


看看 WPF 中的 Pack URI


来源:https://www.codenong.com/4524066/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8941.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?