1.New System.Windows.Forms project;
2.Add reference C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
3.Drag ElementHost from Toolbox to WindowsForms
4.Add reference PresentationCore.dll;
Add reference PresentationFramework.dll;
5.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Forms.Integration; using System.Windows.Media; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Expander expander = new Expander(); expander.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255,0,0)); expander.Header = "WPF Expander"; WindowsFormsHost host = new WindowsFormsHost(); host.Child = new MonthCalendar(); expander.Content = host; label1.Text = "WPF expander control in System.Windows.Forms"; elementHost1.Child= expander; } } }
. Both Color types have a FromArgb static method, so you can create one Color from the other by passing this method the A, R, G, and B values from the source Color.
. To get a Windows Forms font size from a WPF font size, multiply the value by 0.75. To get a WPF font size from a Windows Forms font size, divide the value by 0.75.