views:

22

answers:

1

Hi, i would like to build a Template for my (edit)Buttons in Silverlight 4. Therefor i want to include the Images as a embedded ressource.

so my question is: How can i use the embedded ressource images in the template for my button?

The ControlTemplate (TargetTyoe="Button") is located i one external Ressources.xml.

regards Christoph

+1  A: 

In Silverlight you should be using "Resource", never "Embedded Resource" as the build action for resources.

The MSDN Reference on Resource Files gives a very good overview of resources in Silverlight and the URIs you should use to reference them. It also goes over the default fallback mechanisms used when the referenced file is not immediately found.

In general, you would reference an image source by a path relative to the referencing XAML like this:

<Button>
    <Image Source="path/to/myimage.png"/>
</Button>

If the embedded image resource is located in a different assembly from the referencing XAML, you can use the short assembly name and component keyword like this:

<Button>
    <Image Source="/MyShortAssemblyName;component/path/to/myimage.png"/>
</Button>
Dan Auclair
Hi Dan, thank you for your tip! I had to use the second approach (with assemblyname), as the Button is defined as a ControlTemplate and used in several Usercontrols and therefor cannot use the relative path.
Christoph