Class WindowUtilities

WPF Helpers for MM

System.Object
  MarkdownMonster.Windows.WindowUtilities
public class WindowUtilities : object

Class Members

MemberDescription

Constructor

BitmapSourceToBitmap

Converts a bitmap source to a bitmap Make sure to dispose the bitmap

public static Bitmap BitmapSourceToBitmap(BitmapSource source)

BitmapToBitmapSource

public static BitmapSource BitmapToBitmapSource(Bitmap bmp)

CenterWindow

Centers a WPF window on the screen. Considers DPI settings

public static void CenterWindow(Window window)

DoEvents

Idle loop to let events fire in the UI

Use SPARINGLY or not at all if there is a better way but there are a few places where this is required.

public static void DoEvents()

EnsureWindowIsVisible

Ensures that the window rendered is visible and fitting on the currently active screen.

public static void EnsureWindowIsVisible(Window window)

FindAnchestor

Finds a type of element in the parent chain of an element

public static T FindAnchestor(DependencyObject current)

FindVisualChild

Finds a particular type of control in the children of a top level control

public static T FindVisualChild(DependencyObject obj)

FixFocus

Forces lost focus on the active control in a Window to force the selected control to databind. Typical scenario: Toolbar clicks (which don't cause a focus change) don't see latest control state of the active control because it doesn't know focus has changed. This forces the active control to unbind

public static void FixFocus(Window window,     Control control)

GetDpi

public static UInt32 GetDpi(IntPtr hwnd,     DpiType dpiType)

public static UInt32 GetDpi(Point point,     DpiType dpiType)

public static UInt32 GetDpi(Window window,     DpiType dpiType)

GetDpiRatio

public static decimal GetDpiRatio(Window window)

public static decimal GetDpiRatio(IntPtr hwnd)

GetNestedTreeviewItem

Retrieves a nested TreeViewItem by walking the hierarchy. Specify a root treeview or treeviewitem and it then walks the hierarchy to find the item

public static TreeViewItem GetNestedTreeviewItem(object item,     ItemsControl treeItem)

GetScreenDimensions

Returns the active screen's size in pixels

public static Rectangle GetScreenDimensions(Window window)

InvalidateMenuCommands

Invalidates a menu control and all of its subitems by checking Command.IsEnabled property if a command exists

public static void InvalidateMenuCommands(Menu menu)

InvalidateSubmenuCommands

public static void InvalidateSubmenuCommands(MenuItem menuItem)

IsDispatcherDisabled

Check to see if the Dispatcher is currently not active which can happen internally in WPF rendering and cause unexpected exceptions. Check for those edge cases

public static bool IsDispatcherDisabled(Dispatcher dispatcher)

MakeWindowCompletelyTransparent

Call this to make a window completely click through including all controls on it.

public static void MakeWindowCompletelyTransparent(IntPtr hwnd)

SetPerMonitorDpiAwareness

IMPORTANT: This only works if this is called in the immediate startup code of the application. For WPF this means static App() { }.

public static bool SetPerMonitorDpiAwareness(ProcessDpiAwareness type)

WindowToHwnd

Returns IntPtr for an HWND from WPF Window object

public static IntPtr WindowToHwnd(Window window)

Requirements

Namespace: MarkdownMonster.Windows
Assembly: markdownmonster.exe

© West Wind Technologies, 1996-2021 • Updated: 02/14/20
Comment or report problem with topic