Use a embedded Image in a Button Template in Silverlight 4
I would like to build a Template for my (edit)Buttons in Silverlight 4. Therefore I want to include the Images as a embedded resource.
So my question is: How can I use the embedded ressource images in the template for my button?
The ControlTemplate (TargetType="Button") i开发者_StackOverflows located in one external Ressources.xml.
regards Christoph
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>
精彩评论