C# 在WPF中显示图像datagrid模板字段

C# 在WPF中显示图像datagrid模板字段,c#,wpf,linq-to-sql,wpfdatagrid,C#,Wpf,Linq To Sql,Wpfdatagrid,如何使用LINQ to SQL将图像(存储在SQL数据库中)显示到WPF中datagrid模板字段中的图像控件。这允许您扩展它们。因此,假设您是一个链接类,其属性如下所示: public byte[] Image {get; set;} 可以使用如下属性添加到分部类 public ImageSource imageSource { get { var Img = new BitmapImage(); Img.BeginInit()

如何使用LINQ to SQL将图像(存储在SQL数据库中)显示到WPF中datagrid模板字段中的图像控件。这允许您扩展它们。因此,假设您是一个链接类,其属性如下所示:

public byte[] Image {get; set;}
可以使用如下属性添加到分部类

public ImageSource imageSource
{
    get
    {
            var Img = new BitmapImage();
            Img.BeginInit();
            Img.StreamSource = new System.IO.MemoryStream((byte[])Image);
            Img.EndInit();
            return Img;
     }
 }
然后,在模板控件的模板中,您只需输入以下内容:

<DataGridTemplateColumn Header="Image" >
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Source="{Binding imageSource}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>