SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
WinForms and WPF: An Integrated Approach


The concept of reuse of code with “software building blocks” has been in practice since long. In
the .NET framework, user controls are the quintessential building blocks that give you a simple
yet powerful way to build a set of visual components into a more complex and appealing one.
Another way of doing this would be by using WinForms and WPF (Windows Presentation
Foundation).

WPF is an advanced technology used for rendering user interfaces in Windows-based
applications. It was first released as part of the .NET Framework 3.0. However, WPF utilizes
DirectX instead of relying on the older GDI subsystem. WinForms user controls can be built and
embedded in WinForms applications, and likewise WPF user controls can be built and embedded
in WPF applications.

Hybrids can be built using WinForms and WPF and then WPF controls can be embedded in a
WinForms application or vice versa. Developing WPF application development is easy but
migrating existing WinForms projects to WPF involves a lot of work and effort.

WPF and Windows Forms present two varied architectures for creating application interfaces. Common
interoperation scenarios are provided by the System. The two most important classes that implement
interoperation capabilities are WindowsFormsHost and ElementHost. The latter is an easy method that
is used to integrate WinForms and WPF. It can also be used to place a WPF UIElement on the
WinForms control. ElementHost enables hosting of WPF controls inside a form and on the other
hand WPF supplies the WindowsFormsHost class that allows hosting of WinForms controls
inside a WPF window.

WPF and Windows Forms Interoperation

Both technologies need to have the appropriate keyboard input processing for interoperation
between the WPF and Windows Forms to take place. A hybrid control has a control from one
technology nested in a control from the other technology, which is known as nested
interoperation. A multilevel hybrid control will have more than one level of hybrid control
nesting.

Following are interoperation scenarios that are supported when a WPF control hosts a WinForms
control:

      The WPF can host one or more Windows Forms controls using code.
      It may control one or more Windows Forms controls using XAML.
      It may host a master/detail form with a WPF master and Windows Forms details.
      It may host Windows Forms container controls that contain other Windows Forms
       controls.
   It may host one or more ActiveX controls and master/detail form with a Windows Forms
       master and WPF details
      It may host hybrid controls using code or XAML.

Integrating WinForms and WPF using ElementHost

The ElementHost control resides in the WindowsFormsIntegration assembly. This control is
responsible for loading the WPF control and painting it. Following is a step-by-step guide:

   1. First create a user control in WPF by creating a StackPanel inside the grid with a
      TextBlock and a Button. In order to view a WPF Event, hookup an event handler to the
      Button.
   2. Create a WinForm Host for this user control and then create a new Winform project and
      add a reference to the dlls- PresentationCore.dll, PresentationFramework.dll,
      WindowsBase.dll, WindowsFormsIntegration.dll and the WPF DLL which is already
      created.
   3. To view interoperability between WPF and WinForms, drag a WinForms label and
      button and hook it to an event handler.
   4. In the Form Load handler, create an ElementHost. Since the WPF control’s assembly
      reference is already added, creation an object of the WPF user control can be done.
   5. The control cannot be added to the Form’s control collection since the Form object has
      no idea how to draw the WPF control. To do this, make use of the ElementHost control
      that takes in the user control as its child control and adds it to the WinForm.

WPF controls can be embedded in a WinForms application or WinForms controls in a WPF
application, using a simple adapter. Due to this inherent symmetry, hybrid applications can be
easily built, mixing controls from the other platform.

Más contenido relacionado

Más de Talentica Software

Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaTalentica Software
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryTalentica Software
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsTalentica Software
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player DevelopmentTalentica Software
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile TechnologiesTalentica Software
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - HadoopTalentica Software
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case StudyTalentica Software
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTalentica Software
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentTalentica Software
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 

Más de Talentica Software (15)

Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

WinForms and WPF: An Integrated Approach

  • 1. WinForms and WPF: An Integrated Approach The concept of reuse of code with “software building blocks” has been in practice since long. In the .NET framework, user controls are the quintessential building blocks that give you a simple yet powerful way to build a set of visual components into a more complex and appealing one. Another way of doing this would be by using WinForms and WPF (Windows Presentation Foundation). WPF is an advanced technology used for rendering user interfaces in Windows-based applications. It was first released as part of the .NET Framework 3.0. However, WPF utilizes DirectX instead of relying on the older GDI subsystem. WinForms user controls can be built and embedded in WinForms applications, and likewise WPF user controls can be built and embedded in WPF applications. Hybrids can be built using WinForms and WPF and then WPF controls can be embedded in a WinForms application or vice versa. Developing WPF application development is easy but migrating existing WinForms projects to WPF involves a lot of work and effort. WPF and Windows Forms present two varied architectures for creating application interfaces. Common interoperation scenarios are provided by the System. The two most important classes that implement interoperation capabilities are WindowsFormsHost and ElementHost. The latter is an easy method that is used to integrate WinForms and WPF. It can also be used to place a WPF UIElement on the WinForms control. ElementHost enables hosting of WPF controls inside a form and on the other hand WPF supplies the WindowsFormsHost class that allows hosting of WinForms controls inside a WPF window. WPF and Windows Forms Interoperation Both technologies need to have the appropriate keyboard input processing for interoperation between the WPF and Windows Forms to take place. A hybrid control has a control from one technology nested in a control from the other technology, which is known as nested interoperation. A multilevel hybrid control will have more than one level of hybrid control nesting. Following are interoperation scenarios that are supported when a WPF control hosts a WinForms control:  The WPF can host one or more Windows Forms controls using code.  It may control one or more Windows Forms controls using XAML.  It may host a master/detail form with a WPF master and Windows Forms details.  It may host Windows Forms container controls that contain other Windows Forms controls.
  • 2. It may host one or more ActiveX controls and master/detail form with a Windows Forms master and WPF details  It may host hybrid controls using code or XAML. Integrating WinForms and WPF using ElementHost The ElementHost control resides in the WindowsFormsIntegration assembly. This control is responsible for loading the WPF control and painting it. Following is a step-by-step guide: 1. First create a user control in WPF by creating a StackPanel inside the grid with a TextBlock and a Button. In order to view a WPF Event, hookup an event handler to the Button. 2. Create a WinForm Host for this user control and then create a new Winform project and add a reference to the dlls- PresentationCore.dll, PresentationFramework.dll, WindowsBase.dll, WindowsFormsIntegration.dll and the WPF DLL which is already created. 3. To view interoperability between WPF and WinForms, drag a WinForms label and button and hook it to an event handler. 4. In the Form Load handler, create an ElementHost. Since the WPF control’s assembly reference is already added, creation an object of the WPF user control can be done. 5. The control cannot be added to the Form’s control collection since the Form object has no idea how to draw the WPF control. To do this, make use of the ElementHost control that takes in the user control as its child control and adds it to the WinForm. WPF controls can be embedded in a WinForms application or WinForms controls in a WPF application, using a simple adapter. Due to this inherent symmetry, hybrid applications can be easily built, mixing controls from the other platform.