I have a problem.
I want to write ALL things programically in C#, without VS Designer.
So, I'm creating an image and and DataGrid (and I'm adding it as a child of MainWindow Grid):
Image img = new Image();
Uri uri = new Uri(@"C:\d1.jpg");
img.Source = new System.Windows.Media.Imaging.BitmapImage(uri);
DataGrid dg = new DataGrid();
grid1.Children.Add(dg);
Then I want to add 4 columns for example, 3 of text and one of image. So at first I need to create a DataTable and DataRow with sample data:
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
dt.Columns.Add("Column3");
dt.Columns.Add("Column4", typeof(Image)); // type of image!
DataRow dr = dt.NewRow();
dr[0] = "aaa";
dr[1] = "bbb";
dr[2] = "ccc";
dr[3] = img; // add a sample image
dt.Rows.Add(dr);
Now I have a DataTable with 4 columns and 1 row of data.
Then all I need to do is to set ItemsSource of DataGrid like this:
dg.ItemsSource = dt.DefaultView;
What I'm doing wrong? Why on the final grid there is System.Windows.Controls.Image in a row instead of real image? Do I need to bind it or something?
All things I need to do programically, without designer.
How to display real image instead of that string?