How to use Resource object as a children of a Panel using xaml?
Suppose I has an Image object in my Resource Dictionary like this:
<Image x:Key="Theme_Icon_Microphone" Source="Images/icon_microphone.png"/>
I want to use t开发者_Go百科his object in DockPanel
<DockPanel>
<!-- My Image object -->
</DockPanel>
Don't use an Image
as a static resource because you will only be able to use it once. Instead put a BitmapImage
in resources and reference that from your Image
:
<Grid>
<Grid.Resources>
<BitmapImage UriSource="http://thecybershadow.net/misc/stackoverflow.png" x:Key="image"/>
</Grid.Resources>
<DockPanel>
<Image Source="{StaticResource image}"/>
</DockPanel>
</Grid>
精彩评论