General utility methods for working with WPF.
Classes |
|
struct | RECT |
Data type created for marshalling to a
Windows API RECT.
More... |
|
Public Member Functions |
|
static int | GetWindowRect (IntPtr hWnd, out RECT lpRect) |
P/Invokes GetWindowRect from the Windows
API. |
|
Static Public Member Functions |
|
static void | ForceUiUpdate () |
Allows all pending Dispatcher messages to be
processed before continuing. |
|
static Point | ConvertToPixels (Point deviceIndependentUnits, Visual visual) |
Convert a point from WPF's device
independent units to pixels based on the Visual's presenter's DPI
setting. |
|
static Rect | ConvertToPixels (Rect deviceIndependentUnits, Visual visual) |
Convert a Rect from WPF's device independent
units to pixels based on the Visual's presenter's DPI setting.
|
|
static Point | ConvertToDeviceIndependentUnits (Point pixels, Visual visual) |
Convert a point from pixels to WPF's device
independent units based on the Visual's presenter's DPI setting.
|
|
static Rect | ConvertToDeviceIndependentUnits (Rect pixels, Visual visual) |
Convert a Rect from pixels to WPF's device
independent units based on the Visual's presenter's DPI setting.
|
|
static Matrix | GetDeviceTransformMatrix (Visual visual) |
Get the current device transform, used to
apply DPI settings among other things, for rendering the given
Visual. |
|
static Rect | GetNativeWindowRectInPixels (IntPtr hWnd) |
Gets a native window's location and
dimensions in pixels. |
|
static void | CenterWindowToNativeOwner (Window window) |
Centers a WPF Window to a native Win32 owner
window. |
static void CSharpUtilities::WpfUtilities::ForceUiUpdate | ( | ) | [inline, static] |
Allows all pending Dispatcher messages to be processed before continuing.
Avoid overuse of this method. Generally, WPF does a better job of managing message processing priorities than this brute-force approach.
static Point CSharpUtilities::WpfUtilities::ConvertToPixels | ( | Point | deviceIndependentUnits, |
Visual | visual | ||
) | [inline, static] |
Convert a point from WPF's device independent units to pixels based on the Visual's presenter's DPI setting.
deviceIndependentUnits | WPF point to convert. |
visual | Visual providing the DPI setting. |
static Rect CSharpUtilities::WpfUtilities::ConvertToPixels | ( | Rect | deviceIndependentUnits, |
Visual | visual | ||
) | [inline, static] |
Convert a Rect from WPF's device independent units to pixels based on the Visual's presenter's DPI setting.
deviceIndependentUnits | WPF Rect to convert. |
visual | Visual providing the DPI setting. |
static Point CSharpUtilities::WpfUtilities::ConvertToDeviceIndependentUnits | ( | Point | pixels, |
Visual | visual | ||
) | [inline, static] |
Convert a point from pixels to WPF's device independent units based on the Visual's presenter's DPI setting.
pixels | Point in pixel coordinates to convert. |
visual | Visual providing the DPI setting. |
static Rect CSharpUtilities::WpfUtilities::ConvertToDeviceIndependentUnits | ( | Rect | pixels, |
Visual | visual | ||
) | [inline, static] |
Convert a Rect from pixels to WPF's device independent units based on the Visual's presenter's DPI setting.
pixels | Rect in pixel coordinates to convert. |
visual | Visual providing the DPI setting. |
static Matrix CSharpUtilities::WpfUtilities::GetDeviceTransformMatrix | ( | Visual | visual | ) | [inline, static] |
Get the current device transform, used to apply DPI settings among other things, for rendering the given Visual.
visual | Visual with the desired rendering context. |
static int CSharpUtilities::WpfUtilities::GetWindowRect | ( | IntPtr | hWnd, |
out RECT | lpRect | ||
) |
P/Invokes GetWindowRect from the Windows API.
hWnd | IntPtr wrapping the native window handle. |
lpRect | Out parameter returning the dimensions of the native window. |
static Rect CSharpUtilities::WpfUtilities::GetNativeWindowRectInPixels | ( | IntPtr | hWnd | ) | [inline, static] |
Gets a native window's location and dimensions in pixels.
hWnd | Handle to the native window. |
static void CSharpUtilities::WpfUtilities::CenterWindowToNativeOwner | ( | Window | window | ) | [inline, static] |
Centers a WPF Window to a native Win32 owner window.
For centering a WPF Window to a WPF owner window, it suffices to set Window.WindowStartupLocation to CenterOwner. Unfortunately, this does not work when centering a WPF window on a native owner, at least when the owner is maximized.
To center a Window at its startup, call CenterWindowToNativeOwner from a Window.SourceInitialized event handler. CenterWindowToNativeOwner requires the Window's HwndSource and Visual to have been created in order to translate to Device Independent Units.
window | Window to center |