• North American Sales: 1-800-231-8588
  • Global Contacts
  • My Account
Infragistics Infragistics
Menu
  • North American Sales: 1-800-321-8588
  • My Account
    • Sign In/Register
  • Design & DevelopmentDesign & Develop
    • Best Value
      Infragistics Ultimate The complete toolkit for building high performing web, mobile and desktop apps.
      Indigo.Design Use a unified platform for visual design, UX prototyping, code generation and application development.
    • Web
      Ignite UI for Angular Ignite UI for JavaScript Ignite UI for React Ultimate UI for ASP.NET Indigo.Design
    • Desktop
      Ultimate UI for Windows Forms Ultimate UI for WPF
      Prototyping
      Indigo.Design
    • Mobile
      Ultimate UI for Xamarin Ultimate UI for iOS Ultimate UI for Android
    • Automated Testing Tools
      Test Automation for Micro Focus UFT: Windows Forms Test Automation for Micro Focus UFT: WPF Test Automation for IBM RFT: Windows Forms
  • UX
    • Indigo.Design Desktop Collaborative prototyping and remote usability testing for UX & usability professionals
    • Indigo.Design A Unified Platform for Visual Design, UX Prototyping, Code Generation, and App Development
  • Business Intelligence
    • Reveal Embedded Accelerate your time to market with powerful, beautiful dashboards into your apps
    • Reveal App Empower everyone in your organization to use data to make smarter business decisions
  • Team Productivity
  • Learn & Support Support
    • Help & Support Documents
    • Blogs
    • Forums
    • Product Ideas
    • Reference Applications
    • Customer Stories
    • Webinars
    • eBook & Whitepapers
    • Events
  • Free Trials
  • Pricing
    • Product Pricing / Buy Online
    • Renew Existing License
    • Contact Us
WPF
  • Product Platforms
  • More
WPF
WPF Using the Infragistics WinGrid in a WPF Application
  • Blog
  • Files
  • Wiki
  • Mentions
  • Tags
  • More
  • Cancel
  • New
WPF requires membership for participation - click to join
  • WPF
  • Configuring the XamTab Control
  • Creating a Custom Summary for the XamDataGrid
  • Defining a Custom Path in the XamCarousel
  • Enabling Row Summaries in the XamDataGrid
  • Exporting the XamDataGrid to Excel
  • Hosting a WPF Control in a Windows Forms Application
  • Printing the XamDataGrid with Infragistics.Reports
  • Spell Checking in the XamDataGrid
  • Tangerine -- A WPF Reference Application
  • Using the Infragistics WinGrid in a WPF Application
  • Validation in the XamDataGrid
  • XamDataGrid :: Copying to Excel via the Clipboard
  • XML Databinding with the XamDataGrid

Using the Infragistics WinGrid in a WPF Application

In some scenarios, developers may find themselves in a situation where they are using the Infragistics WinGrid wrapped with some pretty intensive business logic that is going to take a good deal of time to recreate. One possibility that the developer can use is to continue forward with a WPF application and simply re-use the WinGrid in that application. This article demonstrates the necessary libraries to do that.

The first thing that needs to be done is to add references to the WindowsFormsIntegration dll and if you have a separate project hosting your WinForms control include that as well. With the addition of this WindowsFormsIntegration dll, you will be able to add a WindowsFormsHost component to your WPF application. To Display your Windows Forms control simply set the Child property and ensure you have a reference to the control. The following code snippet shows a WinGrid and a Carousel on the same Window.

<Window x:Class="XamWinFormsInteropSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="517" Width="680"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        xmlns:WinGrid="clr-namespace:xamWinGrid;assembly=xamWinGrid"
 	  Loaded="Window_Loaded">
    <Grid x:Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="162*" />
            <RowDefinition Height="100*" />
        </Grid.RowDefinitions>
        <WindowsFormsHost Name="windowsFormsHost1">
            <WinGrid:xamWinGrid x:Name="xamWinGrid1" />
        </WindowsFormsHost>
        <igDP:XamDataCarousel Name="xamDataPresenter1" Grid.Row="1" />
    </Grid>
</Window>

One other thing that can be done is in the user-control for the WindowsForms control; you can have a public property that exposes anything on the underlying controls that you may want to have access to in the WPF application. In this example, I will expose the DataSource property so that I can bind to a NorthWind dataset:

//Windows Forms User-Control
public System.Collections.IEnumerable DataSource
{
set
      {
      	this.ultraGrid1.DataSource = value;
}
}

 

To set up binding in a hybrid scenario, you can use the System.Windows.Forms.BindingSource control. An example from Microsoft is well documented here: http://msdn.microsoft.com/en-us/library/ms742687.aspx . That sample is the basis for the binding listed in this sample:

//WPF Application
private System.Windows.Forms.BindingSource nwBindingSource;
private NwindDataSet nwDataSet;
private NwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter = 
    new XamWinFormsInteropSample.NwindDataSetTableAdapters.CustomersTableAdapter();

        
public Window1()
{
InitializeComponent();
      this.nwDataSet = new NwindDataSet();
      this.nwDataSet.DataSetName = "nwDataSet";

      this.nwBindingSource = new System.Windows.Forms.BindingSource();
      this.nwBindingSource.DataSource = this.nwDataSet;

}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.customersTableAdapter.ClearBeforeFill = true;
      this.customersTableAdapter.Fill(this.nwDataSet.Customers);

 	this.MainGrid.DataContext = this.nwBindingSource;
      this.xamDataPresenter1.DataSource = this.nwBindingSource;
      this.xamWinGrid1.DataSource = this.nwBindingSource;

      BindingListCollectionView cv = 
CollectionViewSource.GetDefaultView(this.nwBindingSource) as 
BindingListCollectionView;

cv.CurrentChanged += new EventHandler(cv_CurrentChanged);
            
}

void cv_CurrentChanged(object sender, EventArgs e)
{
BindingListCollectionView cv = sender as BindingListCollectionView;
      this.nwBindingSource.Position = cv.CurrentPosition;
}

After doing this, you have officially included a Windows Forms Control in your WPF Application:

For additional information on this subject check out these links:

  • Property Mapping: http://msdn.microsoft.com/en-us/library/ms788729.aspx
  • General Issues with Interop: http://blogs.msdn.com/scoberry/archive/2006/09/01/735844.aspx
  • WPF
  • WinGrid
  • Windows Forms
  • Interop
  • Share
  • History
  • More
  • Cancel
Related
Recommended