【问题标题】:Load image from resource in xaml从 xaml 中的资源加载图像
【发布时间】:2012-09-10 16:05:28
【问题描述】:

我有一个以这种方式链接的 xaml 资源

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="AudioPitchShiftStyle.xaml"/>
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

</Window.Resources>     

insite AudioPitchShiftStyle.xaml 我已经把这个声明

<Image Source="img/play.png" x:Key="play" />

如何使用源键通过代码实现ImageBitmap?

【问题讨论】:

    标签: wpf image resources resourcedictionary


    【解决方案1】:

    您可以从资源字典中获取。

    <Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary 
                      Source="Resources/MyResourceDictionary.xaml">
                    </ResourceDictionary>
                    <ResourceDictionary 
                      Source="Resources/OthersStyle.xaml">
                    </ResourceDictionary>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>
        <Grid>
            <Image Source="/WPFDemo;component/Images/AddResourceDictionary.jpg"></Image>
        </Grid>
    

    【讨论】:

      【解决方案2】:

      抱歉,我的意思是使用 C#。不管怎样,我想办法了。

      ResourceDictionary dicto = this.Resources.MergedDictionaries[0];
      Image myImage = (Image)dicto["play"];
      img.Source = myImage.Source;
      

      同样感谢你:-)

      【讨论】:

        猜你喜欢
        • 2012-11-15
        • 2023-03-11
        • 1970-01-01
        • 2021-04-18
        • 1970-01-01
        • 2011-08-13
        • 1970-01-01
        • 1970-01-01
        • 2013-03-12
        相关资源
        最近更新 更多