2013-12-16 66 views
0

夥計們我需要WPF頁面上的datagridview。在WPF頁面上使用windows窗體控件

我用這個

public WindowsFormsHost HOST = new WindowsFormsHost(); 

然後instanttiated我的datagridview作爲

System.Windows.Forms.DataGridView gridview = new System.Windows.Forms.DataGridView(); 

然後,使用一個數據表我填充數據網格視圖

//使已知的WPF天然控制應用

HOST.Child = gridview; 
    //Displaying the column headers (from datatable). 
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 

爲什麼會這樣?

回答

2

您應該將'HOST'添加到WPF窗口,而不是添加'gridview'。

this.Children.Add(HOST); 
相關問題