Take the 2-minute tour ×

I'm new to WP7 programming but have XP with other platforms, i am just running through all the basics so i can get to know the language but i have hit a roadblock I've entered a source for my background image:

<Grid x:Name="LayoutRoot">
        <ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">

And the image shows up as a background in the design tab that is next to the XAML but when i debug and the emulator starts its just a black screen no background image, what have i missed? i have tried other ways of setting a background like:

<Grid x:Name="LayoutRoot">

but the same thing happens I've tried a few other ways also but again nothing, I'm sure I've missed something I should have caught.

share|improve this question
Is build action for the image set to "content"? –  Soroush Mirzaei Nov 12 '12 at 17:22
Well when i look at the properties of the background in the solution explorer it says that it is set to Content –  michael Nov 12 '12 at 17:31
add comment

1 Answer

The path


exists on your dev machine, not on any Windows Phone 7+ device.

Remember, users will be downloading your app from the store, then running it on their phones. How would they possibly access your hard drive and get that image?

Unfortunately, since the design surface allows you to do this, it can of course be confusing to a new developer.

What you should do is add your image to your project as a Resource, then reference the resource via a pack URI (don't click on that link unless you want to scare yourself silly).

To add it as a resource, simply add the image to the root of your WP7 project, right click on it, select Properties, and then change the build action to Resource (not Embedded Resource, mind you).

Next, you have to construct a pack URI for this resource. This is ... not easy. You can use the tools in Visual Studio to do this, by editing the properties of your ImageBrush in the designer. This is the simplest, and recommended, route. All you have to do is edit the ImageSource of your ImageBrush in the Properties tool window, and select the image from the list of available images in the solution.

The other way is to manually construct the pack URI. For example, you could take the following

/[project assembly name];component/Background1.jpg

replace [project assembly name] with the name of your assembly (no extensions), and use it as your ImageSource value. You can find the correct project assembly name by looking at the Assembly Name under the Application section of the project properties.

<ImageBrush ImageSource="/MyWp7Application;component/Background1.jpg"/>

Note, depending on how your project folder structure is constructed, this URI may be different. Constructing the correct URI outside of the tools provided is a task deserving of another question.

share|improve this answer
He asked about the emulator, not the device –  LivingThing Oct 12 '13 at 9:49
@LivingThing: The emulator is a virtual device. It can't access the filesystem on the development machine. Think. –  Will Oct 14 '13 at 12:53
add comment

Your Answer


