XAML ImageBrush using BitmapImage without URI

I have the following XAML that displays the cover for a book using a URI:

<Rectangle.Fill>
    <ImageBrush ImageSource="{Binding CoverUrl}" />
</Rectangle.Fill>

However, the image that I would like to use is not located on the disk anywhere or is not accessible via the URI; it comes from the binary I am parsing into BitmapImage.

When I create an object BitmapImagethrough the code, the resulting objects BaseUriand UriSourceare null. How can I force a ImageBrushuse BitmapImagethat is in memory instead of reading it from a URI?

+3
source share
1 answer

ImageSource ImageSource, Uri string... , Uri. ImageBrush , ImageSource

<Rectangle.Fill>
    <ImageBrush ImageSource="{Binding Cover}" />
</Rectangle.Fill>


private ImageSource _cover;
public ImageSource Cover
{
    get
    {
        if (_cover == null)
        {
            _cover = LoadImage();
        }
        return _cover;
    }
}
+4

Source: https://habr.com/ru/post/1715450/


All Articles