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.
精彩评论