我正在使用WindowsFormHost,以便能夠在我的WPF應用程序 (以此開始,How to instantiate a Datagridview(in code behind))中使用gridview。WPF控件的鑄造
,並着手爲
public WindowsFormsHost HOST = new WindowsFormsHost();
我的GridView控件作爲
System.Windows.Forms.DataGridView gridview = new System.Windows.Forms.DataGridView();
(不要忘了引用,請這裏 - http://www.c-sharpcorner.com/uploadfile/mahesh/using-windows-forms-controls-in-wpf/)
我有一個DataTable填充它作爲
table = new System.Data.DataTable();
table.Columns.Add("Object ID");
foreach (string column in columns)
{
table.Columns.Add(column);
}
foreach (string row in rows)
{
drow = table.NewRow();
tit = row.Substring(0, row.IndexOf('$'));
drow[0] = tit.IndexOf('&') > -1 ? tit.Substring(tit.IndexOf('&') + 1) : tit;
table.Rows.Add(drow);
}
//making the native control known to the WPF application
HOST.Child = gridview;
//Displaying the column headers of the listbox(assigned above).
gridview.DataSource = table.DefaultView;
然而,當我在GridView添加到我的WPF窗口
this.Children.Add(gridview); //error at this line
我得到一個錯誤說
cannot convert from 'System.Windows.Forms.DataGridView' to 'System.Windows.UIElement'
爲什麼會這樣? 我的意思是我可以做些什麼來糾正這個問題?
什麼是RootGrid?我的IDE不識別它。 –