Exemplo n.º 1
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 p = win.PointToScreen(new Point(0, GridCaptionHeight.Value));
			WindowUtils.ShowSystemMenu(win, p);
		}
Exemplo n.º 2
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.º 3
0
        protected override void OnClick()
        {
            switch (CurrentWinSysType)
            {
            case CurrentWinSysType.Minimize:
                WindowUtils.Minimize(window);
                break;

            case CurrentWinSysType.Maximize:
                WindowUtils.Maximize(window);
                break;

            case CurrentWinSysType.Restore:
                WindowUtils.Restore(window);
                break;

            case CurrentWinSysType.Close:
                window.Close();
                break;

            default:
                throw new ArgumentException("Invalid CurrentWinSysType");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 protected override void OnSourceInitialized(EventArgs e)
 {
     base.OnSourceInitialized(e);
     WindowUtils.UpdateWin32Style(this);
 }