Embedding Our Gantt Software VARCHART XGantt in WPF

Embedding Our Gantt Software VARCHART XGantt .NET in WPF Applications

The rich functionality of our Gantt software VARCHART XGantt is also available in WPF applications. For integrating Windows Forms controls into WPF-Windows, Microsoft offers the WindowsFormsHost control that lets you use the .NET edition of VARCHART XGantt within a WPF-Windows as well. Below, please find the description of two alternative approaches:

Precondition: Adding required references

In both cases, to use the WindowsFormsHost control, the references to WindowsFormsIntegration, System.Windows.Forms and of course NETRONIC.XGantt have to be created.

Alternative 1: Integration by way of XAML code of the WPF Windows (Window1.xaml)

This approach integrates our Gantt software VARCHART XGantt within the XAML code:

<Window x:Class="WpfApplication1.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:ne="clr-namespace:NETRONIC.XGantt;assembly=NETRONIC.XGantt"

Title="Hosting XGantt .NET in WPF" Height="400" Width="500">

<Grid x:Name="grid1">

<WindowsFormsHost Margin="41,27,36,30" Name="windowsFormsHost1">

<ne:VcGantt Name="vcGantt1" Height="300" Width="450">

</WindowsFormsHost>

</Grid>

</Window>

 

Alternative 2: Integration by way of Code-Behind of the WPF Windows (Window1.xaml.cs)

This approach does not integrate our Gantt software VARCHART XGantt by way of using XAML code but by using code-behind in C#. For this reason, the XAML code does not contain any specific characteristics, it is just a standard description of a WPF Windows.

<Window x:Class="WpfApplication1.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Hosting XGantt .NET in WPF" Height="400" Width="500">

 

<Grid x:Name="grid1">

</Grid>

</Window>

 

Now the WindowsFormsHost object is created in code-behind and a VcGantt object is added to this object as child.

using System.Windows.Forms.Integration;

using NETRONIC.XGantt;namespace WpfApplication1

{

/// Interaction logic for Window1.xaml

public partial class Window1 : Window

{

WindowsFormsHost windowsFormsHost1 = null;

VcGantt vcGantt1 = null;

public Window1()

{

   InitializeComponent();

   windowsFormsHost1 = new   System.Windows.Forms.Integration.WindowsFormsHost();

   vcGantt1 = new VcGantt();

   windowsFormsHost1.Child = vcGantt1;

   grid1.Children.Add(windowsFormsHost1);

}

}

}

 

Using the property pages for configuration

As, unfortunately, neither alternative offers the use of XGantt.NET's property pages, we recommend you to create a Windows form within the project so that this comfortable way of configuration is still available. You can then place another XGantt instance onto this form and carry out the desired settings on the property pages. This configuration can be exported as *.ini file and afterwards be reimported into the VcGantt object of the WPF Windows.

public Window1()

{

InitializeComponent();

VcGantt vcGantt1 = (VcGantt) windowsFormsHost1.Child; // needed with alternative 1 only!

vcGantt1.InitializeForWebService();

vcGantt1.ImportConfiguration("Name_of_Configuration_file.ini");

}

The NETRONIC components VARCHART XNet.NET and VARCHART XTree.NET can of course also be embedded in WPF applications in a similar way.

Helpful Links