Installation


Using DXFReaderNET Component inside a WPF app


Here’s how you can use .NET Framework 4.8 Windows Forms components inside a WPF (.NET Framework 4.8) app via WindowsFormsHost (WPF ↔ WinForms interop).

1) Target the right framework

This works when your WPF app targets .NET Framework (not .NET 6/7/8).
In Visual Studio: Project → Properties → Application → Target framework → .NET Framework 4.8.

2) Add the required references

Add references to these assemblies:

  • WindowsFormsIntegration (contains WindowsFormsHost)

  • System.Windows.Forms

Right click on "Dependencies" line on "Soultion Explorer":



Browse and add the DXFReaderNET dll:

3) XAML: host DXFReaderNET control

Add the namespace for the interop host:

<Window x:Class="DXFReaderNET_WPFApp.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:local="clr-namespace:DXFReaderNET_WPFApp"
        mc:Ignorable="d"
        xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        xmlns:legacy="clr-namespace:DXFReaderNET;assembly=DXFReaderNET"
        Title="DXFReaderNET WPF App" Height="450" Width="800" Loaded="Window_Loaded">
    <Grid>
        <wfi:WindowsFormsHost x:Name="DXFReaderNET" >
            <legacy:DXFReaderNETControl x:Name="myDXFReaderNET" />
        </wfi:WindowsFormsHost>
    </Grid>
</Window>

4) Code-behind (C#)

 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     myDXFReaderNET.ShowGrid = true;
     myDXFReaderNET.ReadDXF(@"..\..\test.dxf");
     myDXFReaderNET.Refresh();
     myDXFReaderNET.ZoomCenter();
 }

Sample program for using DXFReaderNET Component inside a WPF app


Warning!
All samples, data, places and images in this section are only for tutorial. They are fictitious and may not correspond to real cases.

Any similarities to actual persons or places is merely coincidental.