Wpf 从另一个程序集加载图像';s在XAML中的resx文件

Wpf 从另一个程序集加载图像';s在XAML中的resx文件,wpf,xaml,Wpf,Xaml,我有两个组件,比如assembly1和assembly2 在assembly2中有一个XAML文件。在这个XAML文件中,我想创建一个图像 我要做的是将此图像的源设置为assembly1中resx文件中的位图 <Image Name="image1" Stretch="Fill" Source="???" /> 如何在XAML中正确引用该位图文件?有一个简单的“仅限XAML”解决方案吗?好的,所以我假设没有“仅限XAML”的解决方案 相反,在调用WPF控件的Loaded事件后,

我有两个组件,比如assembly1和assembly2

在assembly2中有一个XAML文件。在这个XAML文件中,我想创建一个图像

我要做的是将此图像的源设置为assembly1中resx文件中的位图

<Image Name="image1" Stretch="Fill" Source="???" />


如何在XAML中正确引用该位图文件?有一个简单的“仅限XAML”解决方案吗?

好的,所以我假设没有“仅限XAML”的解决方案

相反,在调用WPF控件的Loaded事件后,我会这样做:

Assembly coreAssembly = Assembly.GetAssembly(typeof (otherAssembly.Resources));
var resourceManager = new ResourceManager("otherAssembly.Resources", coreAssembly);

// get image from core resources
Bitmap completeImage = (Bitmap) resourceManager.GetObject("Complete");

// apply image to WPF image
var memoryStream = new MemoryStream();
completeImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
bitmapImage.EndInit();

this.myWpfImage.Source = bitmapImage;