Sharing images across projects in Xamarin

五迷三道 提交于 2019-12-24 06:36:03

问题


I'd like to use the same images in multiple device apps in Xamarin.

I have a PCL core library and have started using MVVMCross. What's the best approach to accomplish this? Can I embed them as a resource in the Core library and access it in my Andriod/iOs project, or is it better to use add as link?


回答1:


You can in theory embed these as binary resources in the PCL project and can then access them as byte[] via GetResourceStream and from there can then get them decoded in your UI projects. This would require some work to setup and would make it impossible to use the images in the xib editor, in the android XML, etc

More easily, you can also share these image files using 'Add as link' and then allow each individual platform to optimize and package the files - each platform is good at this - eg Android with its different dpi drawable folders and IOS with its 2x image packaging. This technique also works well with the xib and XML designers.

However, in practice I generally find I don't share these image files between projects - instead on most commercial projects, the PhotoShop guys insist on giving me icons, dividers, and other chrome images which are unique to each platform.



来源:https://stackoverflow.com/questions/18130779/sharing-images-across-projects-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!