The function is implemented in three steps:
1. Add two references: windowsformsintegration. dll (responsible for integrating WPF and Windows), system. Windows. forms.
2. Add two references to the XAML file (in bold ):
3. Implement the control you want to add in the XAML coding area:
In the original article, the datagridview control is added:
<WFI: windowsformshost>
<! -- Set some properties on Windows Forms control in XAML -->
<WF: datagridview X: Name = "datagridview" dock = "fill" selectionmode = "fullrowselect"/>
</WFI: windowsformshost>
:
I added the numericupdown control:
<Grid Height = "0" margin = "146,0, 0,116 "minheight =" 20 "minwidth =" 20 "name =" grid1 "verticalignment =" bottom "horizontalalignment =" Left "width =" 50 ">
<WFI: windowsformshost>
<WF: numericupdown X: Name = "nupcounter" Maximum = "100"> </WF: numericupdown>
</WFI: windowsformshost>
</GRID>
<Window X: class = "crossbowdemo. mainwindow"
Xmlns: WFI = "CLR-namespace: system. Windows. Forms. Integration; Assembly = windowsformsintegration"
Xmlns: WF = "CLR-namespace: system. Windows. forms; Assembly = system. Windows. Forms"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "hosting Windows Forms control in WPF"
Height = "300"
Width = "650"
Resizemode = "noresize"
Loaded = "windowloadedhandler"
>
</WINDOW>