, DataGrid DataGridTextColumns, AutoGeneratingColumn . DataGridTemplateColumn, ( DataTable). .
:
xaml part
<DataGrid Name="ChannelDataGrid" AutoGeneratingColumn="ChannelDataGrid_OnAutoGeneratingColumn">
<DataGrid.Resources>
<DataTemplate x:Key="ImgCell">
<Image Source="{Binding Path=Img}"/>
</DataTemplate>
</DataGrid.Resources>
</DataGrid>
:
private void InitializeDataTable()
{
System.Data.DataTable DataTable = new System.Data.DataTable
{
Columns = {"Test #", "Img", "Min Range", "Max Range", "Result"}
};
Uri uri = new Uri(@"C:/Users/User/Desktop/szagdoga/error.png");
for (int i = 6; i < 50; i++)
DataTable.Rows.Add(ExcelFile[0, i], uri, ExcelFile[1, i], 0, 0);
ChannelDataGrid.ItemsSource = DataTable.DefaultView;
}
private void ChannelDataGrid_OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyName == "Img")
{
e.Column = new DataGridTemplateColumn
{
CellTemplate = (sender as DataGrid).Resources["ImgCell"] as DataTemplate,
HeaderTemplate = e.Column.HeaderTemplate,
Header = e.Column.Header
};
}
}