Silverlight - 资源文件的路径 - ResourceHelper

Silverlight - 资源文件的路径 - ResourceHelper,第1张

概述Kan的blog 总结了如何在xaml中引用三种类型的文件:Resource, Content, None   对于引用Resource类型的文件,使用Assembly Unified Uri是最方便的, 写了一个helper来方便生产Images文件夹下的图片路径:   public class ResourceHelper     {              private Resource

Kan的blog 总结了如何在xaml中引用三种类型的文件:Resource,Content,None

 

对于引用Resource类型的文件,使用Assembly UnifIEd Uri是最方便的,写了一个helper来方便生产Images文件夹下的图片路径:

 

public class ResourceHelper
    {     
        private ResourceHelper() { }
        private static string _assemblyShortname;
        private static string GetAssemblyShortname()
        {
            if (_assemblyShortname == null)
            {
                Assembly a = typeof(ResourceHelper).Assembly;              
                _assemblyShortname = a.ToString().Split(',')[0];
            }
            return _assemblyShortname;
        }

        public  static string BuildImageResourcePath(string filename)
        {
            //assuming the file is under folder "images"
            return string.Format("/{0};component/images/{1}",GetAssemblyShortname(),filename);
        }
       
    }

 

代码中引用一个图片可以:

 img.source = new System.windows.Media.Imaging.BitmAPImage(                 new Uri(ResourceHelper.BuildImageResourcePath("myicon.png"),UriKind.relative));

总结

以上是内存溢出为你收集整理的Silverlight - 资源文件的路径 - ResourceHelper全部内容,希望文章能够帮你解决Silverlight - 资源文件的路径 - ResourceHelper所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1047454.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存