Sunday, 19 December 2010

Using a WinForms user control in WPF

During WPF application development we are bound to face situation where we cannot port the WinForms user control to WPF, and will be forced to use the control in WPF window.

The steps below help us achieve that:

1) Add <WindowsFormsHost> control to the window

If needed remove the Height, Width and Margin property and use 'Stretch' for HorizontalAlignment and VerticalAlignment - to simulate the Dock=Fill.

2) Now we can add any WinForms control to the WindowsFormsHost.

For example if we have WinForms user control named UserControl1, we can write this code:
UserControl1 uc1 = new UserControl1();
winHost.Child = uc1;

- cheers

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

C# Reactive Extensions - Buffer and Window

I was going through Buffer and Window in RX, thought a few examples would help clear the differences. First create a buffer of even numbe...