SoFunction
Updated on 2025-03-06

Methods to introduce WindowsForms controls in WPF

This article describes the method of introducing WindowsForms controls in WPF. Share it for your reference, as follows:

environment:

[1]WindowsXP with SP3

[2]VS2008 with SP1

text:

Step1: Introducing Windows Forms to existing projects

Right-click [References]->Select [Add Reference]->[.NET] tab

Added [WindowsFormsIntegration] and []

Step2: Add in XAML file

[S2-1] Add to namespace reference:

xmlns:wf="clr-namespace:;assembly="
xmlns:wfi="clr-namespace:;assembly=WindowsFormsIntegration"

[S2-2] Add to Windows Forms control

<wfi:WindowsFormsHost Name="winFormsContainer" ="2" Margin="0,5,0,0">
 <wf:ListView x:Name="listView1" Margin="0,2,0,0" Name="listView1"/>
</wfi:WindowsFormsHost>

Step3: Operate WindowsForms control in CS code

Icon icon = new Icon(@"");
 imageList2 = new ();
(icon);
 = imageList2;

For more information about C# related content, please check out the topic of this site:Summary of C# form operation skills》、《Tutorial on the usage of common C# controls》、《Summary of WinForm control usage》、《Summary of thread usage techniques for C# programming》、《Summary of C# operation skills》、《Summary of XML file operation skills in C#》、《C# data structure and algorithm tutorial》、《Summary of C# array operation skills"and"Introduction to C# object-oriented programming tutorial

I hope this article will be helpful to everyone's C# programming.