开发者

How to use an image defined as an XAML resource as an image control?

Let's say we have the image defined as below.

<Grid.Resources>
    <Image x:Key="SomeKey" Source="Path\To\The\Image.png" />
</Grid.Resources>

I want to use it as an image con开发者_StackOverflow中文版trol somewhere. I try:

<Image Source="{StaticeResource SomeKey}" /> 

But that doesn't work.


You should use it as

<ContentControl Content="{DynamicResource SomeKey}" />

Hope that helps!

ps. Note that we must use DynamicResource instead of StaticResource so that if the image is used many times, a new/separate cloned image is created for each of those cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜