Provides DPI information for a window.
Exemplo n.º 1
0
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            this.source = (HwndSource)HwndSource.FromVisual(this);

            // calculate the DPI used by WPF; this is the same as the system DPI
            var matrix = source.CompositionTarget.TransformToDevice;

            this.dpiInfo = new DpiInformation(96D * matrix.M11, 96D * matrix.M22);

            if (this.isPerMonitorDpiAware) {
                this.source.AddHook(WndProc);

                RefreshMonitorDpi();
            }
        }
Exemplo n.º 2
0
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            this.source = (HwndSource)HwndSource.FromVisual(this);

            // calculate the DPI used by WPF; this is the same as the system DPI
            var matrix = source.CompositionTarget.TransformToDevice;

            this.dpiInfo = new DpiInformation(96D * matrix.M11, 96D * matrix.M22);

            if (this.isPerMonitorDpiAware)
            {
                this.source.AddHook(WndProc);

                RefreshMonitorDpi();
            }
        }
Exemplo n.º 3
0
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            _source = (HwndSource)PresentationSource.FromVisual(this);
            if (_source?.CompositionTarget == null)
            {
                return;
            }

            // calculate the DPI used by WPF; this is the same as the system DPI
            var matrix = _source.CompositionTarget.TransformToDevice;

            DpiInformation = new DpiInformation(96D * matrix.M11, 96D * matrix.M22);

            if (!_isPerMonitorDpiAware)
            {
                return;
            }
            _source.AddHook(WndProc);
            RefreshMonitorDpi();
        }
Exemplo n.º 4
0
        protected sealed override void OnSourceInitialized(EventArgs e)
        {
            Logging.Here();

            base.OnSourceInitialized(e);

            _hwndSource = (HwndSource)PresentationSource.FromVisual(this);
            if (_hwndSource?.CompositionTarget != null)
            {
                var matrix = _hwndSource.CompositionTarget.TransformToDevice;
                _dpi         = new DpiInformation(BaseDpi * matrix.M11, BaseDpi * matrix.M22);
                DeviceScaleX = matrix.M11;
                DeviceScaleY = matrix.M22;
            }
            else
            {
                _dpi = new DpiInformation(BaseDpi, BaseDpi);
            }

            _dpi.UpdateUserScale(AppearanceManager.Instance.AppScale);
            Logging.Debug($"DPI: {_dpi}");

            LoadLocationAndSize();
            UpdateReferenceSizeForDpiAwareness();

            if (IsPerMonitorDpiAware)
            {
                Logging.Debug("Per-monitor DPI-aware");
                _hwndSource?.AddHook(WndProc);
            }
            else
            {
                Logging.Error("Not per-monitor DPI-aware!");
            }

            RefreshMonitorDpi();
            UpdateScaleRelatedParams();
            OnSourceInitializedOverride();
        }
Exemplo n.º 5
0
        private void OnSourceInitialized(object sender, EventArgs e) {
            _source = (HwndSource)PresentationSource.FromVisual(this);
            if (_source?.CompositionTarget == null) return;

            // calculate the DPI used by WPF; this is the same as the system DPI
            var matrix = _source.CompositionTarget.TransformToDevice;
            DpiInformation = new DpiInformation(96D * matrix.M11, 96D * matrix.M22);

            if (!_isPerMonitorDpiAware) return;
            _source.AddHook(WndProc);
            RefreshMonitorDpi();
        }