Igor/10Tec
2011-01-19T14:51:34Z
Our iGrid.NET control can be used in WPF forms using the standard technique of Windows Forms controls hosting provided by WPF's WindowsFormsHost element. That's enough easy to do, and here is a step-by-step sample.

First, add a reference to the TenTec.Windows.iGridLib.iGrid.dll library to your project. Then define a new namespace (let it be "TenTec") to use it when we will place iGrid.NET on the form. It should look like the following:

Quote:

<Window x:Class="iGrid.NET_in_WPF_Form.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TenTec="clr-namespace:TenTec.Windows.iGridLib;assembly=TenTec.Windows.iGridLib.iGrid.v5.0"
Title="MainWindow" Height="300" Width="400" Loaded="Window_Loaded">



Then drop the WindowsFormsHost element on the form and place iGrid.NET in it:

Quote:

<WindowsFormsHost Margin="5">
<TenTec:iGrid x:Name="iGrid1" />
</WindowsFormsHost>



The full XAML listing for our form will look like this:

<Window x:Class="iGrid.NET_in_WPF_Form.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:TenTec="clr-namespace:TenTec.Windows.iGridLib;assembly=TenTec.Windows.iGridLib.iGrid"
        Title="MainWindow" Height="300" Width="400">

    <DockPanel LastChildFill="True">

        <TextBlock DockPanel.Dock="Top" Margin="10" FontWeight="Bold">iGrid for WindowsForms.NET on a WPF form:</TextBlock>

        <WindowsFormsHost Margin="5">
            <TenTec:iGrid x:Name="iGrid1" />
        </WindowsFormsHost>

    </DockPanel>

</Window>
If you wish, you can add some code that populates this iGrid with data say in the form's Loaded event:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
	iGrid1.Cols.Count = 2;
	iGrid1.Rows.Count = 10;
	iGrid1.Cells[0, 0].Value = 123;
}

Attached you'll find a screenshot of a working WPF form with iGrid.NET and the full source code of the sample created using VS 2010 and C#.

Pay attention to the fact that we added a call to Application.EnableVisualStyles() to the Startup event of our app (see the App.Xaml.cs file) to enable the usage of visual styles to draw the constituent parts of our iGrid:

public partial class App : Application
{
	protected override void OnStartup(StartupEventArgs e)
	{
		base.OnStartup(e);
		System.Windows.Forms.Application.EnableVisualStyles();
	}
}

If we do not do this, iGrid will work ok but will be drawn using the "outdated" 3D Windows style.
File Attachment(s):
iGrid.NET in WPF Form.zip (10kb) downloaded 147 time(s).
Igor/10Tec attached the following image(s):