public static MonitorUtils Current(IWindowEx windowWrapper = null) { windowWrapper = windowWrapper ?? throw new ArgumentNullException(nameof(windowWrapper)); if (!Cache.ContainsKey(windowWrapper)) { var item = new MonitorUtils(windowWrapper); Cache.Add(windowWrapper, item); windowWrapper.ApplicationView.Consolidated += new WeakReferenceEx <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(IWindowEx windowWrapper) { MonitorUtils = MonitorUtils.Current(windowWrapper); WindowWrapper = windowWrapper ?? throw new ArgumentNullException(nameof(windowWrapper)); var di = windowWrapper.DisplayInformation; di.OrientationChanged += new Common.WeakReferenceEx <DeviceUtils, DisplayInformation, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => di.OrientationChanged -= w.Handler }.Handler; var av = windowWrapper.ApplicationView; av.VisibleBoundsChanged += new Common.WeakReferenceEx <DeviceUtils, ApplicationView, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler }.Handler; }