What is the correct build action for Windows Phone 7 image files?

I am working on a Windows Phone 7 application, and after a little Googling it seems that for the images that I added to my Visual Studio project, I need to set the build action to “Content” in order to be able to reference the images in my application.

However, the Windows Phone List application project template contains an image (ArrowImg.png) in which its assembly action is set to Resource and is still available for reference from the application.

I was wondering if anyone could confirm that we should definitely use the content assembly action or is there some way to access the images added to the project using the Resource Creation Action, as shown in the sample project, which we should instead of this?

+6
visual-studio windows-phone-7 silverlight
source share
2 answers

If you set the action to “Content”, the image will be included “as is” in XAP. If you set the action to Resource, the image will be embedded in the shared DLL.

In many situations, you can use either. There may be a performance problem or another problem using one and not the other, but I do not know and never noticed.

Why is it worth it? If I don’t need to specifically make it a resource, I use content.

Using current (beta) tools, I saw that VS complains that images directly referenced in XAML should be set to Resource (if Content is installed), but the application works fine with any of them. Hope this is a problem that will be addressed in RTM tools.

For more information, see the discussion in What are the various “Build action” settings in Visual Studio project properties and what do they do?

+10
source share

Whether the assembly action is performed correctly.

It is also worth paying attention when solving problems related to the assembly action is the path you use.

I saw how few people run into the problem because they assume that they incorrectly set the build action.

You can set the assembly action in any way to meet your requirements, when you need to take the time it takes to download, you just need to set the path to fit.

Additional information on this topic.

Set image source in C #

You can liken content to lazy loading a version of resources.

The difference is that you will carry the performance of all resources when assemblies are loaded to run your application.

Content, on the other hand, is a hit in performance until you use it.

The more suitable, the better, depending on the case.

Please note that the path to help resources and content is as seen here.

//Uri uri = new Uri("/Resources/Images/MyImage.jpg", UriKind.Relative); // Content Uri uri = new Uri("/PhoneApp;component/Resources/Images/MyImage.jpg", UriKind.Relative); // Resource BitmapImage imgSource = new BitmapImage(uri); image1.Source = imgSource; 
+3
source share

All Articles