Home > Microsoft .Net Development Tips > Microsoft Office Development > Letting WinForms and WPF controls coexist
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

MICROSOFT OFFICE DEVELOPMENT

Letting WinForms and WPF controls coexist


Brian Eastwood, Site Editor
06.11.2007
Rating: --- (out of 5)


Office Development Channel
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Your CEO just returned from a Windows Presentation Foundation demo and demands to see some bright, shiny objects in your company's client applications. Trouble is, you have been running WinForms apps for several years, thank you very much, and you surmise that turning a drop-down list into a 3D carousel of images highlighted by drop shadows is far more trouble that it is worth.

Not so fast, Brian Noyes, chief architect at the consultancy IDesign, told developers at Tech Ed 2007. It's rather simple to host WPF controls in a WinForms application, he said, and it's just as easy to do it the other way around.

This sort of interoperability makes sense for several reasons, Noyes continued. The underlying reason is that, though WinForms and WPF controls render differently, underneath both are just components that are .NET class instances.

WinForms is a comprehensive set of controls with a familiar, and mature, designer, while the toolset for building WPF controls is both in its infancy and, at the moment, better suited for designers. At the same time, the video, animation and rich text capabilities of Windows Presentation Foundation are simply not possible with WinForms.

Therefore, Noyes said, a company ho


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Microsoft Office Development
Downloadable MSDN library released for VS 2008 SP 1
Check the MSDN Virtual Labs for regular, compelling new content
Windows XP SP3 pack includes new XML parser, enhanced IP security
Book excerpt: Building personalized solutions in SharePoint 2007
Book excerpt: Building document management solutions in SharePoint 2007
XAML as an everywhere presentation format
Where are the Visual Studio 2008 Tools for Office?
ClickOnce: Automated smart client deployment
Book excerpt: SharePoint 2007 and content types
Update desktops automatically using the AppUpdater component

Smart client application development best practices
As some target upstart Silverlight, WinForms and ASP.NET remain strong
VB code download home page
Picking a .NET smart client communications technology
ClickOnce: Automated smart client deployment
Update desktops automatically using the AppUpdater component
Volta aims to ease multi-tier client application development
.NET development in the trenches
Vista Gadgets: Petits Fours for your programming menu
SearchVB.com's Podcast Page
Visual Studio 2008 Learning Guide: Smart client development

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


lding in its hands a huge WinForms app with hundreds of controls will probably want to incorporate WPF controls incrementally. In contrast, an application with only a few WinForms controls is a good candidate for being hosted in Windows Presentation Foundation.

To host WPF in a WinForms app, developers simply need to add to the controls collection the ElementHost, which resides in the System.Windows.FormsIntegration namespace. It is also important to add a reference to the custom control library and a reference to where that control and its base classes live. "It takes about four lines of code to get this stuff going," Noyes said.

The process for hosting WinForms controls in a WPF app is the same, only in this case the host is called the WindowsFormsHost.

Now, this sort of interoperability is not without its challenges, Noyes noted:

Ultimately, for the moment it is easier to host WinForms apps in Windows Presentation Foundation that vice versa, Noyes said. At the same time, like all good things WinForms development will eventually come to an end. "The libraries are going to be in the .NET Framework until time eternal, but you're going to want to go to WPF to evolve your application further," he noted.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts