public static MonitorUtils Current(WindowWrapper windowWrapper = null) { windowWrapper = windowWrapper ?? WindowWrapper.Current(); if (!Cache.ContainsKey(windowWrapper)) { var item = new MonitorUtils(windowWrapper); Cache.Add(windowWrapper, item); windowWrapper.ApplicationView().Consolidated += new WeakReference <MonitorUtils, ApplicationView, object>(item) { EventAction = (i, s, e) => Cache.Remove(windowWrapper), DetachAction = (i, w) => windowWrapper.ApplicationView().Consolidated -= w.Handler }.Handler; } return(Cache[windowWrapper]); }
private DeviceUtils(WindowWrapper windowWrapper) { MonitorUtils = MonitorUtils.Current(windowWrapper); WindowWrapper = windowWrapper ?? WindowWrapper.Current(); var di = windowWrapper.DisplayInformation(); di.OrientationChanged += new WeakReference <DeviceUtils, DisplayInformation, object>(this) { EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => di.OrientationChanged -= w.Handler }.Handler; var av = windowWrapper.ApplicationView(); av.VisibleBoundsChanged += new WeakReference <DeviceUtils, ApplicationView, object>(this) { EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler }.Handler; }