我将Image.Source属性绑定到下面显示的属性的结果。WPF BitmapSource图像源
public BitmapSource MyImageSource
{
get
{
BitmapSource source = null;
PngBitmapDecoder decoder;
using (var stream = new FileStream(@"C:\Temp\logo.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
if (decoder.Frames != null && decoder.Frames.Count > 0)
source = decoder.Frames[0];
}
return source;
}
}
由于某些原因,在呈现图像期间(DeepCopy PresentationCore程序集),这是失败的。我敢肯定的形象是不是贪官,我可以成功显示同一图像W/O绑定
<Image Name="FooImage" Source="/logo.png" />
我必须在代码中的图像源绑定,因为我最终将创建从一个base64字符串的图像流。
任何人都知道这是一个错误w/WPF?还是我做错了什么?
噢谢天谢地,我一直在努力解决这个问题。谢谢! – gerrod 2010-03-15 12:55:31