Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the correct build action for windows phone 7 image files?

I've been working on a Windows Phone 7 app, and after a bit of Googling it seems that for images that I have added to the Visual Studio project, I need to set the build action to "Content" in order to be able to reference the images in my app.

However, the Windows Phone List Application project template includes an image (ArrowImg.png) that has its Build Action set to "Resource", and is still available to be referenced from the application.

I was wondering if anyone could confirm that we should definitely be using the Content build action, or whether there is some way to access images added to a project with the Resource Build Action as shown in the project sample, which we should be using instead?

like image 778
Henry C Avatar asked Sep 03 '10 10:09

Henry C


People also ask

What are build actions?

The build action controls what happens to the file when the project is compiled. This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Build actions in Visual Studio for Mac.

How do you change a build action to an embedded resource?

Click in the solution explorer the file that will be modified. Then hit F4 or click with the right button in the file and then select the "Properties" option. In the Properties window, change Build Action to Embedded Resource.


2 Answers

If you set the action to "Content" the image is included "as-is" in the XAP. If you set the action to "Resource" the image is embedded into a shared DLL.

In a lot of situations you can use either. There may be a performance, or other, issue with using one rather than another but I'm not aware of and have never noticed any.

For what it's worth, unless I need to specifically make it a resource, I use content.

With the current (Beta) tools, I have seen VS complain that images directly referenced in XAML should be set to "Resource" (if set to "Content") but the app works fine with either. Hopefully this is an issue which will be addressed in the 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?

like image 62
Matt Lacey Avatar answered Sep 20 '22 22:09

Matt Lacey


Either build action is correct.

Also worth looking at when resolving issues relating to build action is the pathing you use.

I've seen a fair few people running into trouble with this because they assume they've set their build action inappropriately.

You can set the build action either way to suit your requirements of when to incur the load time cost, you just need to adjust the pathing to suit.

Some more info on the topic from this post.

Set source to image in C#

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

The difference is you will incur the performance hit of all resources when the assemblies are loaded to start your app.

Content, on the other hand, the performance hit is deferred to when you use it.

Which is more suitable will vary on a case by case basis.

Note also that the pathing to reference resources and content is different as can see 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;
like image 30
Mick N Avatar answered Sep 21 '22 22:09

Mick N