In this blog post we will show you how to use the VIBlend
DataGridView for WinForms in a WPF application.
The following code example creates a WinForms DataGrid control with Office2010Black theme in a WPF
application. This example uses a WindowsFormsHost element to place the DataGrid
control within the main window’s root
element. The WindowsFormsHost element could be found in the
WindowsFormsIntegration.dll.
[xaml]
<Window x:Class="HostWinFormsControlInWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viblend="clr-namespace:VIBlend.WinForms.DataGridView;assembly=VIBlendGrid"
Title="Window1" Height="300" Width="300">
<Grid>
<WindowsFormsHost>
<viblend:vDataGridView x:Name="VIBlendDataGrid" VIBlendTheme="OFFICE2010BLACK"/>
</WindowsFormsHost>
</Grid>
</Window>
In order to bind the data grid, you need to do the
following: Click on the Data menu item
in your Visual Studio, then select the “Add new DataSource” item. Browse to the Nwind.mdb which ships with the
WinForms controls installation, choose the Employees table and click finish. In
the code behind, after the InitializeComponent call or in the Load event
handler , bind the data grid to the Employees table.
NwindDataSet dataSet = new NwindDataSet();
EmployeesTableAdapter adapter = new EmployeesTableAdapter();
adapter.Fill(dataSet.Employees);
this.VIBlendDataGrid.DataSource = dataSet.Employees.DefaultView;
this.VIBlendDataGrid.DataBind();
Here is the result: