Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 protected override void OnSourceInitialized(EventArgs e)
 {
     base.OnSourceInitialized(e);
     WindowUtils.UpdateWin32Style(this);
 }