Presents Windows Presentation Foundation (WPF) content within a Win32 window.
Assembly: PresentationCore (in PresentationCore.dll)
Many members of this class are not available in the Internet security zone.
An implements a Win32 window that can contain WPF content. The WPF content in the window is arranged, measured, rendered, and is interactive to input. Because the is specifically designed to interoperate with Win32, this class exposes a number of low-level Win32 features, including:
Specifying window class styles
Specifying window styles
Specifying extended window styles
Hooking the window procedure
Access to the window handle (HWND)
Destroying the window
The class is designed for general interoperability, and is not designed as a managed HWND wrapper. In general, it does not provide managed methods for manipulating the window or properties for inspecting its state. Instead, the class provides access to the Win32 window handle (HWND) via the Handle property, which can be passed via PInvoke techniques to Win32 APIs in order to manipulate the window.
Many aspects of the can only be specified at construction time. To create an , first create an HwndSourceParameters structure and populate it with the desired parameters. These parameters include:
Class, window, and extended window styles. You must PInvoke to change the styles after the window is created. Not all styles can be changed after the window has been created. Consult the Win32 documentation before changing window styles.
Initial position of the window.
Initial size of the window, including whether the size is specified or should be determined from the determined size of the WPF content.
The parent window.
The HwndSourceHook to include in the window procedure chain. If you specify a hook at construction time, it will receive all messages for the window. You can use AddHook to add a hook after the window has been created.
Transparency settings. A top-level window can be configured to blend with the other windows on the desktop according to the per-pixel transparency of the WPF content. To enable this, set the UsesPerPixelOpacity property in the HwndSourceParameters to true. This can only be specified at construction time, and only through the HwndSource(HwndSourceParameters) constructor signature, and it imposes a number of limitations.
An is a regular common language runtime (CLR) object, and its lifetime is managed by the garbage collector. However, since the represents an unmanaged resource, implements IDisposable. Calling Dispose will synchronously destroy the Win32 window immediately if called from the owner thread. If called from another thread, the Win32 window will be destroyed asynchronously. Calling Dispose explicitly from the interoperating code might be necessary for certain interoperation scenarios.
The class implements its own window procedure. This window procedure is used to process important window messages, such as those related to layout, rendering, and input. However, you can also hook the window procedure for your own use. You can specify your own hook during construction by setting the HwndSourceParameters.HwndSourceHook property, or you can also use AddHook and RemoveHook to add and remove hooks after the window has been created. The hooks will be called by last-in, first-out order, which enables your hooks to execute before the built-in processing. The actual hooks are held by a weak reference, so make sure you manage the lifetime of your hook delegate.
For more information about and other interoperation classes, see WPF and Win32 Interoperation Overview.
Notice how the constructors for take parameters that resemble the parameters for Win32 functions such as CreateWindowEx.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.