How to get a list of the assets in the WP7 Content Project?

放肆的年华 提交于 2019-12-23 15:35:35

问题


I can load a textures with:

Texture2D texture = ContentManager.Load<Texture2D>(assetName);

But this throws an exception if the file doesn't exist. Is there a way to determine if a requested asset of a given name actually exists first?

I'm storing a series of assets using suffixed number counters (art001.png, art002.png, ...) and would like to have a simple call preload the textures by just counting through them.


回答1:


It is not possible to iterate through the contents of your XAP file. You'll just have to maintain a list of the assets you wish to load.

I had a similar problem with my app, I ended up writing a simple script that looked in a particular folder for a matching filename pattern and updating a text file. So, I'd run the script before building the app, the text file gets packaged and read in the app to determine what files could be loaded. Or you can skip the trouble and maintain a list in code by hand.




回答2:


You could potentialy use T4. ASP.NET MVC has T4MVC where you use something like:

MVC.Dinners.Views.DinnerForm

instead of:

"DinnerForm"

I'm not sure but it probably uses the T4's code generation on build process. See documentation



来源:https://stackoverflow.com/questions/5530777/how-to-get-a-list-of-the-assets-in-the-wp7-content-project

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