Class WindowUtilities

WPF Helpers for MM

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

Class Members

MemberDescription

Constructor

ActivateWindow

Activates a WPF window even if the window is activated on a separate thread

public static void ActivateWindow(Window window)

AttachThreadInput

public static bool AttachThreadInput(UInt32 idAttach,     UInt32 idAttachTo,     bool fAttach)

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)

BrushToColor

Converts a WPF Color Brush to a System.Drawing Color Often needed for interop

public static Color BrushToColor(Brush brush)

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(Dispatcher dispatcher,     DispatcherPriority priority)

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)

GetForegroundWindow

public static IntPtr GetForegroundWindow()

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)

GetWindowThreadProcessId

public static UInt32 GetWindowThreadProcessId(IntPtr hWnd,     IntPtr ProcessId)

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)

SetForegroundWindow

Force Window to the foreground. This seems to be the only reliable way to get MM to become UI active from within MM when activated externally.

public static IntPtr SetForegroundWindow(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, 2016-2024 • Updated: 11/23/21
Comment or report problem with topic