private void DimOwner() { _dimmedOwner = Owner as DpiAwareWindow; if (_dimmedOwner?.IsDimmed == false) { _dimmedOwner.IsDimmed = true; } else { _dimmedOwner = null; } }
private void UndimOwner() { if (_dimmedOwner != null) { _dimmedOwner.IsDimmed = false; _dimmedOwner = null; } }
/// <summary> /// Initializes a new instance of the <see cref="DpiAwarenessViewModel" /> class. /// </summary> public DpiAwarenessViewModel() { this.wnd = (DpiAwareWindow)App.Current.MainWindow; this.wnd.DpiChanged += OnWndDpiChanged; this.wnd.SizeChanged += OnWndSizeChanged; }
public static void HandleSecondInstanceMessages(DpiAwareWindow window, Action<IEnumerable<string>> handler) { HwndSource hwnd = null; HwndSourceHook hook = (IntPtr handle, int message, IntPtr wParam, IntPtr lParam, ref bool handled) => { if (message == SecondInstanceMessage) { try { handler(ReceiveSomeData()); window.BringToFront(); } catch (Exception e) { Logging.Warning("Can’t handle message: " + e); } } return IntPtr.Zero; }; RoutedEventHandler[] handlers = { null, null }; // loaded handlers[0] = (sender, args) => { window.Loaded -= handlers[0]; try { hwnd = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle); if (hwnd == null) { Logging.Warning("Can’t add one-instance hook: HwndSource is null"); return; } hwnd.AddHook(hook); window.Unloaded += handlers[1]; } catch (Exception e) { Logging.Warning("Can’t add one-instance hook: " + e); hook = null; } }; // unloaded handlers[1] = (sender, args) => { window.Unloaded -= handlers[1]; try { hwnd.RemoveHook(hook); } catch (Exception e) { Logging.Warning("Can’t remove one-instance hook: " + e); hook = null; } }; if (!window.IsLoaded) { window.Loaded += handlers[0]; } else { handlers[0](null, null); } }
public void SetParent(DpiAwareWindow parent) { _parent = parent; }