Scott Davies
Scott Davies

Reputation: 3755

How do you store an image in a Silverlight 3 custom control?

I have created a custom control that will have a bitmap image in it. My project structure is:

Solution
    ProjectName
        Resources
            Actor.png

The XAML I am using is:

<Image x:Name="ActorBitmap" Source="ProjectName;component/Resources/Actor.png />

However, this is not working. I have the build options on the picture set to "Resource" and "Copy Always". Can someone please explain what I'm doing wrong ?

Thanks,

Scott

Upvotes: 0

Views: 142

Answers (1)

Dan Auclair
Dan Auclair

Reputation: 3617

I believe you just need a leading forward slash before the resource location:

<Image x:Name="ActorBitmap" Source="/ProjectName;component/Resources/Actor.png />

There is also no need to set copy to output directory to "Copy Always". Because the build action is set to Resource the image data will be in the assembly itself, and you will not be referencing it from the output directory.

Upvotes: 1

Related Questions