Class WPFWindowWrapper
- Namespace
- VisioForge.Core.UI.WPF
- Assembly
- VisioForge.Core.dll
Window handle wrapper enabling WinForms dialog display in WPF applications.
This class provides a bridge between WPF and WinForms by implementing the IWin32Window interface, allowing WinForms dialogs and controls to be properly parented to WPF windows. Essential for mixed-mode applications that need to display WinForms dialogs (like file dialogs, message boxes, or third-party controls) within a WPF application context.
Key features:
- Implements IWin32Window interface for WinForms compatibility
- Extracts native window handle from WPF windows
- Provides proper parent-child relationship for dialogs
- Ensures correct Z-order and focus behavior
- Enables modal dialog functionality across UI frameworks
Common use cases:
- Displaying WinForms dialogs from WPF applications
- Embedding WinForms controls that require parent handles
- Third-party component integration requiring Win32 handles
- Legacy code integration in modernized WPF applications
Technical implementation:
- Uses WindowInteropHelper to extract native window handle
- Maintains handle reference for dialog lifetime
- Provides seamless interop between WPF and WinForms
Thread safety: Should be created and used on the UI thread as it accesses WPF window handles.
public class WPFWindowWrapper : IWin32WindowInheritance
Implements
Inherited Members
Constructors
WPFWindowWrapper(Window)
Initializes a new instance of the VisioForge.Core.UI.WPF.WPFWindowWrapper class.
Creates a wrapper around a WPF window to enable WinForms dialog integration. The constructor extracts the native window handle from the WPF window using WindowInteropHelper, which provides the Win32 handle needed for WinForms interop.
The extracted handle is stored and exposed through the IWin32Window interface, allowing WinForms dialogs to be properly parented to the WPF window.
Thread safety: Must be called from the UI thread as it accesses WPF window properties.
public WPFWindowWrapper(Window wpfWindow)Parameters
wpfWindowWindow-
The WPF window to wrap for WinForms interop.
Properties
Handle
Gets the native window handle for the wrapped WPF window.
This property implements the IWin32Window interface requirement and provides the Win32 window handle that WinForms dialogs and controls need for proper parent-child relationships.
The handle is extracted once during construction and remains valid for the lifetime of the wrapper object. This handle can be used with any WinForms API that requires a parent window handle.
Thread safety: Safe to access from any thread once initialized.
public nint Handle { get; }