【问题标题】:Using windows forms controls on a WPF page在 WPF 页面上使用 Windows 窗体控件
【发布时间】:2013-12-16 13:05:28
【问题描述】:

伙计们,我需要 WPF 页面上的 datagridview。

我用过这个

public WindowsFormsHost HOST = new WindowsFormsHost();

然后将我的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

为什么会这样?

【问题讨论】:

    标签: c# wpf datagridview wpf-controls type-conversion


    【解决方案1】:

    您应该将“HOST”添加到 WPF 窗口,而不是添加“gridview”。

       this.Children.Add(HOST);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多