Use a embedded Image in a Button Template in Silverlight 4

寵の児 提交于 2020-01-16 18:27:30

问题


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") is located in one external Ressources.xml.

regards Christoph


回答1:


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>


来源:https://stackoverflow.com/questions/3110248/use-a-embedded-image-in-a-button-template-in-silverlight-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!