开发者

How to use Resource object as a children of a Panel using xaml?

开发者 https://www.devze.com 2023-03-05 17:13 出处:网络
Suppose I has an Image object in my Resource Dictionary like this: <Image x:Key=\"Theme_Icon_Microphone\" Source=\"Images/icon_microphone.png\"/>

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

精彩评论

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