如何将自定义ImageSource提供给XAML中的图像

如何将自定义ImageSource提供给XAML中的图像,xaml,windows-phone-7,windows-phone-8,imagesource,bitmapsource,Xaml,Windows Phone 7,Windows Phone 8,Imagesource,Bitmapsource,在XAML中为图像设置ImageSource的一种方法如下: <Image Width="75" Height="75"> <Image.Source> <BitmapImage UriSource={Binding Uri} DecodePixelWidth="75" DecodePixelHeight="75" /> <Image.Source> </Image> <Image Width="

在XAML中为图像设置ImageSource的一种方法如下:

<Image Width="75" Height="75">
    <Image.Source>
        <BitmapImage UriSource={Binding Uri} DecodePixelWidth="75" DecodePixelHeight="75" />
    <Image.Source>
</Image>
<Image Width="75" Height="75">
    <Image.Source>
        <custom:PictureBitmap Picture={Binding Picture} Width="75" Height="75" />
    <Image.Source>
</Image>
虽然BitmapSource是抽象的,但没有解释如何实现它

有人知道如何将自定义对象提供给Image.Source吗

我的应用程序支持Windows Phone Mango(7.5)及以上版本


谢谢

采用附加属性方法解决了问题

要使用自定义逻辑设置图像的Source属性,请执行以下操作:

<Image Width="75" Height="75" my-namespace:PictureBitmap.Source={Binding Picture} />

这个链接非常有用:

另外,我注意到DecodePixelWidth和DecodePixelHeight属性在Mango中不可用

Mango提供PictureDecoder类,但是缺点是它必须在UI线程上使用

<Image Width="75" Height="75" my-namespace:PictureBitmap.Source={Binding Picture} />