我有一个以这种方式链接的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?
答案 0 :(得分:2)
你可以从资源词典中获取。
<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>
答案 1 :(得分:1)
抱歉,我的意思是使用C#。无论如何,我想到了怎么做。
ResourceDictionary dicto = this.Resources.MergedDictionaries[0];
Image myImage = (Image)dicto["play"];
img.Source = myImage.Source;
谢谢你: - )