在 XAML 中为 Image 设置 ImageSource 的一种方法是:
<Image Width="75" Height="75">
<Image.Source>
<BitmapImage UriSource={Binding Uri} DecodePixelWidth="75" DecodePixelHeight="75" />
<Image.Source>
</Image>
此代码包含一个很好的优化,因为一个可能很大的位图将被解码为 75x75 像素。
我希望能够用我的自定义类替换 BitmapImage,如下所示:
<Image Width="75" Height="75">
<Image.Source>
<custom:PictureBitmap Picture={Binding Picture} Width="75" Height="75" />
<Image.Source>
</Image>
我的应用程序实现了映射到数据库表的 Picture 类。图片类具有创建 BitmapImage 实例所需的一切。所以PictureBitmap本质上是BitmapImage的一个适配器。
我是这样开始的:
public class PictureBitmap : BitmapSource
{
// TODO: create Picture Dependency Property
// TODO: create a BitmapImage from Picture
// TODO: implement abstract methods by delegating calls to BitmapImage
}
虽然 BitmapSource 是抽象的,但API 参考并没有说明如何实现它。
有谁知道如何将自定义对象提供给 Image.Source?
我的应用支持 Windows Phone Mango (7.5) 及更高版本。
谢谢!