예제 #1
0
        /// <inheritdoc/>
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

            Debug.Assert(hwndSource != null);
            if (hwndSource != null)
            {
                hwndSource.AddHook(WndProc);
                wpfDpi = new Size(96.0 * hwndSource.CompositionTarget.TransformToDevice.M11, 96.0 * hwndSource.CompositionTarget.TransformToDevice.M22);

                var w = Width;
                var h = Height;
                WindowDpi = GetDpi(hwndSource.Handle) ?? wpfDpi;

                if (!wpfSupportsPerMonitorDpi)
                {
                    double scale = DisableDpiScalingAtStartup ? 1 : WpfPixelScaleFactor;
                    Width  = w * scale;
                    Height = h * scale;

                    if (WindowStartupLocation == WindowStartupLocation.CenterOwner || WindowStartupLocation == WindowStartupLocation.CenterScreen)
                    {
                        Left -= (w * scale - w) / 2;
                        Top  -= (h * scale - h) / 2;
                    }
                }
            }

            WindowUtils.UpdateWin32Style(this);
        }
예제 #2
0
        /// <inheritdoc/>
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

            Debug.Assert(!(hwndSource is null));
            if (!(hwndSource is null))
            {
                hwndSource.AddHook(WndProc);
                wpfDpi = new Size(96.0 * hwndSource.CompositionTarget.TransformToDevice.M11, 96.0 * hwndSource.CompositionTarget.TransformToDevice.M22);

                var w = Width;
                var h = Height;
                WindowDpi = GetDpi(hwndSource.Handle) ?? wpfDpi;
            }

            WindowUtils.UpdateWin32Style(this);
        }
예제 #3
0
        /// <inheritdoc/>
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

            Debug.Assert(hwndSource != null);
            if (hwndSource != null)
            {
                hwndSource.AddHook(WndProc);
                wpfDpi = 96.0 * hwndSource.CompositionTarget.TransformToDevice.M11;

                var w = Width;
                var h = Height;
                WindowDPI = GetDpi(hwndSource.Handle, (int)wpfDpi);

                // For some reason, we can't initialize the non-fit-to-size property, so always force
                // manual mode. When we're here, we should already have a valid Width and Height
                Debug.Assert(h > 0 && !double.IsNaN(h));
                Debug.Assert(w > 0 && !double.IsNaN(w));
                SizeToContent = SizeToContent.Manual;

                if (!wpfSupportsPerMonitorDpi)
                {
                    double scale = DisableDpiScaleAtStartup ? 1 : WpfPixelScaleFactor;
                    Width  = w * scale;
                    Height = h * scale;

                    if (WindowStartupLocation == WindowStartupLocation.CenterOwner || WindowStartupLocation == WindowStartupLocation.CenterScreen)
                    {
                        Left -= (w * scale - w) / 2;
                        Top  -= (h * scale - h) / 2;
                    }
                }
            }

            WindowUtils.UpdateWin32Style(this);
        }