Пример #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);
        }
Пример #4
0
        static void ShowSystemMenu(object o)
        {
            var depo = o as DependencyObject;

            if (depo == null)
            {
                return;
            }
            var win = Window.GetWindow(depo);

            if (win == null)
            {
                return;
            }

            var mwin = win as MetroWindow;

            Debug.Assert(mwin != null);
            var scale = mwin?.WpfPixelScaleFactor ?? 1;

            var p = win.PointToScreen(new Point(0 * scale, GridCaptionHeight.Value * scale));

            WindowUtils.ShowSystemMenu(win, p);
        }