In this article we will discuss about Build Action type of image in Windows Phone.. The image can have Build Action type of Content or Resource. The image is part of XAP in Windows Phone. I will give some performance tips along with how to use Build Action type of image.
Let's write code:
Step 1: Create Silverlight for Windows Phone project.
Step 2: Add two images in the project.
Step 3: Right click on one of the image, select properties and change the Build Action type of one of the image to Content.
Don't change the Build Action type of another image. Let the Build Action to be Resource.
Step 4: Add one image control inside contentpanel of MainPage.xaml. I will add the image which has Build Action is set to Content to this image control.
<Image Name="imgContent" Source="/concierge bell.jpg" Margin="0,-200,0,0" Width="200" Height="200" />
Step 5: Now add another image inside contentpanle of MainPage.xaml. This time I will add the image whose Build Action is Resource. The way we specify path in case the image is set to Resource is different.
<Image Name="imgResource" Source="../concierge bell1.jpg" Margin="0, 300,0,0" Width="200" Height="200"/>
Step 6: Now run the application and you will notice bothe image appear on the Windows Phone screen like below.
So there is no difference. At the end there is only one XAP which contains everything
Let's get dipper into this.
Change the extension of XAP to zip and unzip it.
You will notice there is only image, the image which you can see is the image whose Build Action was set to Content.
Now, where is the other image whose Build Action was set to Resouce. The image whose Build Action was set to Resouce is embedded in the assembly (.dll). It is obvious when image is embedded in the .dll it size will increase. When size of .dll is large the time to load the application will be more. It means your application start up time will be slower.
If image (Build Action set to Resource) is in .dll, once image is loaded next access will be quicker.
So if you want to access images quicly set the Build Action type of image as Resource. If you want quick start of your application with images set the Build Action type of image as Content.
This ends the article of Image Build Action - Content VS Resource.