检查 WPF 中是否存在打包资源 [英] Check if a packed resource exists in WPF
本文介绍了检查 WPF 中是否存在打包资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果 Uri 中存在资源,是否可以检查代码,例如:
Is there a way to check in code if a resource exists at an Uri such as:
"pack://application:,,,/MyResource.jpg"
推荐答案
只需砍掉 pack://application:,,,/字符串的一部分,然后在路径的剩余部分执行 File.Exists.
Just chop off the pack://application:,,,/ part of the string and do a File.Exists on the remaining part of the path.
您发布的代码段指向一个位于正在运行的应用程序根目录中的文件,名为 MyResource.jpg.
Your snippet you posted is pointing to a file that lives in the root of the running application and is called MyResource.jpg.
这篇关于检查 WPF 中是否存在打包资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文