Windows Forms Interoperability



UserControl on a Windows Form (Design Time)

Add a reference to "Windows.Base"
Add a reference to "System.Xml"
Add a reference to "Presentation.Core"
Right click on your project and select (Add > New Item)
Choose "UserControl (WPF)" and provide a name of "UserControl2"


Build your project.


Drag an ElementHost control from the Toolbox onto your Windows Form
Change the Dock property to Fill
Resize the windows from to match the size of the WPF user control
Right click and choose, Select Hosted Content
Click on the very small arrow in the top right corner
In the Selected Hosted Content, select your usercontrol



UserControl on a WIndows Form (Run Time)


System.Windows.Forms.Integration.ElementHost ehost = new System.Windows.Forms.Integration.ElementHost(); 
ehost.Size = new Size(10,10)
MyUserControl ocontrol = new MyUserControl();
ehost.Child = ocontrol;
this.Controls.Add(ehost);



Windows Control on a WPF panel

Add a reference to:
WindowsFormIntegration
System.Windows.Forms


Create a grid element to insert your windows forms panel into
In the Design view display the Properties window
Click the Events tab and double click on the Loaded event
Add the following code to the Loaded event




WPFWindows Equivalent
CollectionViewSourceBindingSource
ListBoxCheckedListBox
ContextMenuContextMenuStrip
DataGridDataGridView
DatePickerDateTimePicker
No equivalentErrorProvider
No equivalentBindingNavigator
No equivalentColorDialog
No equivalentFolderBrowserDialog
No equivalentNotifyIcon
No equivalentFontDialog
No equivalentPageSetupDialog
No equivalentLinkLabel
No equivalentHelpProvider
ScrollBarHScrollBar, VScrollBar
Frame, WebBrowserWebBrowser
SliderTrackBar
ToolBar with compositionToolStrip, ToolStripPanel, ToolStripContainer, ToolStripDropDown, ToolStripDropDownMenu
DispatchTimerTimer
GridTableLayoutPanel
StatusBarStatusStrip
GridSplitterSplitContainer
MediaPlayerSoundPlayer
ScrollViewerScrollableControl
ImagePictureBox
CanvasPanel


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext