How to get a list of assets in a WP7 content project?

I can load textures with:

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

But this throws an exception if the file does not exist. Is there a way to determine if the requested asset of a particular name really exists?

I store a series of assets using suffix number counters (art001.png, art002.png, ...) and would like a simple call to preload the textures by simply counting them.

+4
source share
2 answers

Cannot iterate the contents of your XAP file. You just need to save the list of assets that you want to load.

I had a similar problem with my application, in the end I wrote a simple script that looked in a specific folder for the corresponding file name template and update the text file. So, I ran the script before creating the application, the text file will be packed and read in the application to determine which files can be downloaded. Or you can skip the problem and save the list in code manually.

+7
source

You can potentially use T4 . ASP.NET MVC has T4MVC , where you use something like:

 MVC.Dinners.Views.DinnerForm 

instead:

 "DinnerForm" 

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

+1
source

Source: https://habr.com/ru/post/1346453/


All Articles