简体   繁体   中英

How can I add images form a SQL Server database to a DataGrid?

I'm trying to add some images from a database table to my DataGrid. I don't know how to deal with that. How can I add images to a DataGrid? Or should I use something else? Like a StackPanel?

This is what I got so far:

<DataGrid Name="ImageDataGrid" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" ...>
     <DataGrid.Columns>
          <DataGridTextColumn Binding="{Binding screenshot}"></DataGridTextColumn>
      </DataGrid.Columns>
</DataGrid>

I assume it supposed to be something like this:

<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" >
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="Image">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Width="auto" Height="auto" Source="{Binding Image}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM