J. Doe
J. Doe

Reputation: 167

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>

Upvotes: 1

Views: 152

Answers (1)

igorushi
igorushi

Reputation: 1995

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>

Upvotes: 2

Related Questions