CSharpUtilities::WpfUtilities Class Reference


Detailed Description

General utility methods for working with WPF.

List of all members.

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.

Member Function Documentation

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.

Parameters:
deviceIndependentUnits WPF point to convert.
visual Visual providing the DPI setting.
Returns:
The point converted to pixel coordinates.
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.

Parameters:
deviceIndependentUnits WPF Rect to convert.
visual Visual providing the DPI setting.
Returns:
The Rect converted to pixel coordinates.
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.

Parameters:
pixels Point in pixel coordinates to convert.
visual Visual providing the DPI setting.
Returns:
The point converted to WPF's device independent units.
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.

Parameters:
pixels Rect in pixel coordinates to convert.
visual Visual providing the DPI setting.
Returns:
The Rect converted to WPF's device independent units.
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.

Parameters:
visual Visual with the desired rendering context.
Returns:
Render transform matrix used for the given visual.
static int CSharpUtilities::WpfUtilities::GetWindowRect ( IntPtr  hWnd,
out RECT  lpRect 
)

P/Invokes GetWindowRect from the Windows API.

Parameters:
hWnd IntPtr wrapping the native window handle.
lpRect Out parameter returning the dimensions of the native window.
Returns:
nonzero on success, 0 on failure
static Rect CSharpUtilities::WpfUtilities::GetNativeWindowRectInPixels ( IntPtr  hWnd ) [inline, static]

Gets a native window's location and dimensions in pixels.

Parameters:
hWnd Handle to the native window.
Returns:
The native window's location and dimensions in pixels.
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.

Parameters:
window Window to center

CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities
CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities CSharpUtilities::WpfUtilities