.. _wpf-page:

#########################
|ProductName| with WPF
#########################


.. image:: ../../images/wpf_logo.png
    :height: 64
    :align: right

|ProductName| has (on Windows) a built-in support for Win32 apps. This is implemented by the 
:class:`Win Component <cee::win::WinComponent>`. 
The same component is used for Win32, MFC, Windows Forms and WPF.

See the topic :ref:`c-sharp-users-page` for tips on how to use |ProductName| and this documentation with C#/.NET

*****************
Creating a Viewer
*****************

All HOOPS Envision apps needs a viewer in order to visualize the 3D data. WPF uses the 
:class:`ViewerWin32 <cee::win::ViewerWin32>` found in the :class:`Win Component <cee::win::WinComponent>`. 

For integration towards WPF, you create your own Windows Forms UserControl and implement paint, mouse and other event 
handling towards |ProductName|. The UserControl is inserted into your WPF page using the WindowsFormsHost class. 
A functional viewer with full code is provided in the WpfWindowsFormsHostMinimal example.

Due to limitations in WPF (airspace), you cannot draw other controls on top of the OpenGL rendering done in the |ProductName| 
View class. If you need to have other controls on top of the rendering, you can use a WPF UserControl with 
offscreen rendering and work around this limitation. See the WpfMinimal example for how to do this. This approach will 
have a slight performance penalty.

****************
Example Programs
****************

All .NET examples are provided with a .cproj for use in Visual Studio.

**WPF Minimal**

.. |img_wm| image:: ../../images/example_wpf_minimal.png
   :width: 150

+-----------------------+------------------------------------------------------------------------------------+
| |img_wm|              | **Location**\ : Examples/WinForms/WpfMinimal  |br|                                 |
|                       | A very small example showing the basic requirements for a WPF application.    |br| |
|                       | This uses offscreen rendering which is then copied to an Image in the WPF |br|     |
|                       | UserControl.                                                                       |
+-----------------------+------------------------------------------------------------------------------------+

.. note::
    We recommend to use WindowsFormsHost instead of a WPF UserControl, for performance reasons.

**WPF WindowsFormsHost Minimal**

.. |img_whm| image:: ../../images/example_wpf_windowsformshost_minimal.png
   :width: 150

+-----------------------+------------------------------------------------------------------------------------+
| |img_whm|             | **Location**\ : Examples/WinForms/WpfWindowsFormsHostMinimal  |br|                 |
|                       | A very small example showing the basic requirements for a WPF application |br|     |
|                       | using WindowsFormsHost.                                                            |
+-----------------------+------------------------------------------------------------------------------------+

