RareNCool
RareNCool

Reputation: 436

ImageSource Binding Caches Image

I'm setting a Border's Background property by using an ImageBrush. The ImageSource is bound to an ImageUri property on my Contact object.

<Border>
    <Border.Background>
        <ImageBrush ImageSource="{Binding ImageUri, Mode=OneWay}" AlignmentX="Center" AlignmentY="Center" Stretch="UniformToFill"/>
    </Border.Background>
</Border>

I'm using Azure Blob storage to store the images and it's working fine. However, if I update the image on a contact which already has an image set, my ImageBrush doesn't display the change. I've tried restarting the app and it makes no difference. The image is definitely being updated, as I tried downloading it from the url and it gets the new image. Also, if I reinstall the app it shows the new image correctly. So it would seem that the app is automatically caching the old image and displaying that one instead of the new one. (I already suspected this, since it takes a bit to get the images the first time, but after that it's instant.)

Is there any way to prevent this behaviour?

Upvotes: 0

Views: 321

Answers (1)

RareNCool
RareNCool

Reputation: 436

Apparently you need to explicitly tell it not to cache the image. Replacing my ImageBrush with:

<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="UniformToFill">
    <ImageBrush.ImageSource>
        <BitmapImage CreateOptions="IgnoreImageCache" UriSource="{Binding ImageUri, Mode=OneWay}"/>
    </ImageBrush.ImageSource>
</ImageBrush>

fixed the issue for me.

Upvotes: 2

Related Questions