Developers can integrate the Document Imaging functionality in a .NET WPF application in the same way as in a WinForms application.
One has to add the ActiveX controls to the project References in Visual Studio Solution Explorer:
In order to use the Document Imaging BiDisp Control, in a WPF application, one has to use the WindowsFormHost class from System.Windows.Forms.Integration namespace in the WindowsFormsIntegration.dll assembly.
For more information about the WindowsFormHost class, please refer to the following link:
This class is able to load WinForm controls, and it is inherited from WPF UIElement, allowing developers to place the control on a WPF user interface.
The following code demonstrates how to use the BiDisp with WindowsFormHost.
The MainWindow.xaml.cs contains the following code:
public partial class MainWindow : Window { public AxBIDISPLib.AxBIDisp BiDisp; public BIDIBLib.BIDIB BiDib; System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainWindow));
public MainWindow() { InitializeComponent(); BiDisp = new AxBIDISPLib.AxBIDisp(); ((System.ComponentModel.ISupportInitialize)(this.BiDisp)).BeginInit(); BiDisp.Location = new System.Drawing.Point(192, 408); BiDisp.Name = "BiDisp"; BiDisp.Size = new System.Drawing.Size(100, 50); BiDisp.TabIndex = 2;
//WindowsFormHost System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); host.Child = BiDisp; RootGrid.Children.Add(host); ((System.ComponentModel.ISupportInitialize)(this.BiDisp)).EndInit(); BiDib = new BIDIBLib.BIDIB();
//Displaying an image on the user interface long dib = BiDib.LoadDIBFromFile(@"c:\temp\myimage.bmp"); //load a document from the hard-drive. BiDisp.hDib = dib;
} } |
The MainWindow.xaml contains the following code:
<Window x:Class="Document_Imaging_Sample_WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:local="clr-namespace:Document_Imaging_Sample_WPF" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="RootGrid"> </Grid> </Window> |
When running the WPF application, the LoadDIBFromFile function call will load the BMP file from the specified location, and display it on the application User Interface.