Shalvin.Com                                                                                                                      Home
WPF Windows Forms Interoperabilty

Despite the power of WPF the shortcoming I found in WPF was the lack of certain controls like a DataGrid.
The solution is either you can create your own control or use the Windows Forms DataGrid.  WPF is having excellent compatibility with Windows Forms, so I chose the latter.
Here is the code:


usingSystem.Data;
using System.Xml;

System.Windows.Forms.DataGrid dg;
System.Windows.Forms.OpenFileDialog ofd;

protected void Window1_Loaded(object sender, RoutedEventArgs e)
{
dg = new System.Windows.Forms.DataGrid();
ofd = new System.Windows.Forms.OpenFileDialog();
windowsFormsHost1.Child = dg;
DataSet ds = new DataSet();
ds.ReadXml("c:\\CategoriesProduct.xml");
dg.DataSource = ds;
}

For this to work you should set a reference to System.Windows.Forms.


Contact : shalvin@gmail.com