Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用不带URI的BitmapImage的XAML ImageBrush_C#_.net_Xaml - Fatal编程技术网

C# 使用不带URI的BitmapImage的XAML ImageBrush

C# 使用不带URI的BitmapImage的XAML ImageBrush,c#,.net,xaml,C#,.net,Xaml,我有以下XAML,它使用URI显示一本书的封面图像: <Rectangle.Fill> <ImageBrush ImageSource="{Binding CoverUrl}" /> </Rectangle.Fill> 但是,我想使用的映像不在任何地方的磁盘上,也不能通过URI访问;它来自一个二进制文件,我将其解析为一个BitmapImage对象 当我通过代码创建BitmapImage对象时,结果对象的BaseUri和UriSource属性为空。

我有以下XAML,它使用URI显示一本书的封面图像:

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

但是,我想使用的映像不在任何地方的磁盘上,也不能通过URI访问;它来自一个二进制文件,我将其解析为一个
BitmapImage
对象


当我通过代码创建
BitmapImage
对象时,结果对象的
BaseUri
UriSource
属性为空。如何让
ImageBrush
使用驻留在内存中的
BitmapImage
,而不是从URI中读取它?

ImageSource属性的类型是ImageSource,而不是URI或字符串。。。实际上,当您为其分配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;
    }
}

私人影像来源(封面);;
公众影像来源封面
{
得到
{
如果(_cover==null)
{
_cover=LoadImage();
}
返回盖;
}
}