开发者

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

开发者 https://www.devze.com 2023-01-30 17:26 出处:网络
Let\'s say we have the image defined as below. <Grid.Resources> <Image x:Key="SomeKey" Source="Path\\To\\The\\Image.png" />

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

精彩评论

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