开发者

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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜