I have an image that needs to be used in my application in several places. I want to define an image only once in the resource dictionary and have my other xaml files just for that definition. I can. The only thing I canβt understand is how to refer to something defined as an xaml element, instead of the attribute inside the xaml attribute.
Here is my ResourceDictionary
# resourceDictionary.xaml
<LinearGradientBrush x:Key="MyGradient" StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="#A5000000" Offset="0"/>
<GradientStop Color="#00000000" Offset="1"/>
</LinearGradientBrush>
<Image x:Key="MyImage" Source="MyGlyph.png" Width="20" Height="20" />
So, in my xaml, I know how to refer to a gradient as an attribute of a control object
<TextBlock Text="Sample Text" Background="{DynamicResource MessageGradient}"/>
But I want to figure out how to reference an image, which is a full-blown control object. This example simply creates a button that has the text "{DynamicResource MyImage}" in the button instead of the image.
<Button>
{DynamicResource MyImage}
</Button>
, , , xaml , ?