Enable WPF/Windows Forms Interoperability with WPF Commands

Windows Presentation Foundation (WPF) can interoperate with Windows Forms, letting you add legacy controls to your new interface—or new WPF controls to your existing Windows Forms applications. Either way, you need to make them play nicely together.

by Rich Quackenbush

Jun 19, 2008

Page 1 of 3

WEBINAR:

On-Demand

Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js

uppose you've been given the green light to use Windows Presentation Foundation (WPF) in the latest version of your user interface. There's just one snag—not all the third party controls critical to your application have a WPF version. Fortunately, WPF has excellent support for legacy controls; however, you'll need to write some glue code to provide the interoperability.

Hosting a Windows Forms Control in WPF The key element for hosting legacy controls in WPF is a special control called, appropriately enough, WindowsFormsHost. Here's a walkthrough of the process for adding a Windows Forms TextBox to a WPF window.

First, create a window and, in the XAML, add the following namespaces to the <Window> tag: