Original: How WPF uses WindowsFormsHost (that is, the WinForm control)
How to use:
1. First, we need to add two dynamic library DLLs to the references in the project (reference), one is. NET Library, the System.Windows.Forms
other one is WindowsFormsIntegration
;
2, after adding two dynamic DLLs, you can find the WindowsFormsHost control in the control library.
3. Put this control into the form, and the corresponding code will be generated automatically in the Xmal code when you finish placing it:
<Grid> <WindowsFormsHost Height="100" HorizontalAlignment="Left" Margin="36,29,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="200" /> </Grid>
4. Then, you need to add two lines of code at the beginning of the Xmal:
xmlns:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:WinFormControls="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
5. This allows you to place the required Windows Form control under WindowsFormsHost.
<windowsformshost Height="196" horizontalalignment="Left" Margin="104,65,0,0" Name="WindowsFormsHost1" verticalalignment= "Top" Width="286" > <Winformcontrols:button Text="Winformbutton" Width="150 "/> </windowsformshost>
How WPF uses WindowsFormsHost (that is, WinForm controls)