コード例 #1
0
        protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case Win32Helper.WM_NCLBUTTONDOWN:     //Left button down on title -> start dragging over docking manager
                if (wParam.ToInt32() == Win32Helper.HT_CAPTION)
                {
                    _model.Descendents().OfType <LayoutAnchorablePane>().First(p => p.ChildrenCount > 0 && p.SelectedContent != null).SelectedContent.IsActive = true;
                    handled = true;
                }
                break;

            case Win32Helper.WM_NCRBUTTONUP:
                if (wParam.ToInt32() == Win32Helper.HT_CAPTION)
                {
                    if (OpenContextMenu())
                    {
                        handled = true;
                    }

                    if (_model.Root.Manager.ShowSystemMenu)
                    {
                        WindowChrome.GetWindowChrome(this).ShowSystemMenu = !handled;
                    }
                    else
                    {
                        WindowChrome.GetWindowChrome(this).ShowSystemMenu = false;
                    }
                }
                break;
            }

            return(base.FilterMessage(hwnd, msg, wParam, lParam, ref handled));
        }
コード例 #2
0
        private void HandleWindowStateChanged()
        {
            //
            // BUG FIX:	Window on minimize would go behind any other windows
            //			on desktop, preventing user from seeing the Windows
            //			minimize animation.
            Topmost = WindowState == WindowState.Minimized;

            if (TemplateRoot != null)
            {
                if (WindowState == WindowState.Normal)
                {
                    TemplateRoot.Margin = new Thickness(0);
                }
                else if (WindowState == WindowState.Maximized)
                {
                    TemplateRoot.Margin = new Thickness(SystemParameters.BorderWidth + 3);
                }
            }
            //else if (WindowState == WindowState.Minimized)
            //{
            //	if (Owner != null)
            //		Owner.WindowState = WindowState.Minimized;
            //}

            if (WindowState == WindowState.Minimized)
            {
                if (Owner != null)
                {
                    Owner.WindowState = WindowState.Minimized;
                }
            }
            else if (WindowState == WindowState.Maximized)
            {
                try
                {
                    //Rect rect = MonitorHelper.MonitorWorkingAreaFromWindow(this);
                    //IntPtr _mHWND = (new WindowInteropHelper(this)).Handle;

                    //int x = (int)rect.Left;
                    //int y = (int)rect.Top;
                    //int cx = (int)rect.Width;
                    //int cy = (int)rect.Height;
                    //UnsafeNativeMethods.SetWindowPos(_mHWND, new IntPtr(-2), x, y, cx, cy - 1, 0x0040);

                    WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                    //_originalResizeBorder = chrome.ResizeBorderThickness;
                    chrome.ResizeBorderThickness = new Thickness(0);
                }
                catch (InvalidOperationException) { }
            }
            else
            {
                if (ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip)
                {
                    WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                    chrome.ResizeBorderThickness = new Thickness(1);                    // _originalResizeBorder;
                }
            }
        }
コード例 #3
0
        private void Initialize()
        {
#if NETFX4
            // NOTE: Lack of contracts: SystemParameters2.Current must ensure non-null value
            Contract.Assume(SystemParameters2.Current != null);
#endif

            _chrome = new WindowChrome
            {
#if NETFX4
                CaptionHeight = SystemParameters2.Current.WindowCaptionHeight,
#elif NETFX45
                CaptionHeight = SystemParameters.WindowCaptionHeight,
#endif
                CornerRadius          = new CornerRadius(0d),
                GlassFrameThickness   = new Thickness(0d),
                NonClientFrameEdges   = NonClientFrameEdges.None,
                ResizeBorderThickness = Parameters.Window.GetResizeBorderThickness(this),
                UseAeroCaptionButtons = false
            };
            _chrome.Freeze();
            if (WindowChrome.GetWindowChrome(this) == null)
            {
                WindowChrome.SetWindowChrome(this, _chrome);
            }

            Initialized += OnInitializedInternal;
            Loaded      += OnLoadedInternal;

            var resizeBorderThicknessPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(Parameters.Window.ResizeBorderThicknessProperty, typeof(Window));
            if (resizeBorderThicknessPropertyDescriptor != null)
            {
                resizeBorderThicknessPropertyDescriptor.AddValueChanged(this, OnResizeBorderThicknessChanged);
            }
        }
コード例 #4
0
 protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 {
     if (msg != 161)
     {
         if (msg == 165)
         {
             if (wParam.ToInt32() == 2)
             {
                 if (this.OpenContextMenu())
                 {
                     handled = true;
                 }
                 if (!this._model.Root.Manager.ShowSystemMenu)
                 {
                     WindowChrome.GetWindowChrome(this).ShowSystemMenu = false;
                 }
                 else
                 {
                     WindowChrome.GetWindowChrome(this).ShowSystemMenu = !handled;
                 }
             }
         }
     }
     else if (wParam.ToInt32() == 2 && this._model.RootDocument != null)
     {
         this._model.RootDocument.IsActive = true;
     }
     return(base.FilterMessage(hwnd, msg, wParam, lParam, ref handled));
 }
        protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case Win32Helper.WmNclbuttondown:                     //Left button down on title -> start dragging over docking manager
                if (wParam.ToInt32() == Win32Helper.HtCaption)
                {
                    if (_model.RootDocument != null)
                    {
                        _model.RootDocument.IsActive = true;
                    }
                }
                break;

            case Win32Helper.WmNcrbuttonup:
                if (wParam.ToInt32() == Win32Helper.HtCaption)
                {
                    if (OpenContextMenu())
                    {
                        handled = true;
                    }
                    if (_model.Root.Manager.ShowSystemMenu)
                    {
                        WindowChrome.GetWindowChrome(this).ShowSystemMenu = !handled;
                    }
                    else
                    {
                        WindowChrome.GetWindowChrome(this).ShowSystemMenu = false;
                    }
                }
                break;
            }

            return(base.FilterMessage(hwnd, msg, wParam, lParam, ref handled));
        }
コード例 #6
0
ファイル: WindowX.cs プロジェクト: PinkRammy/WindowX
        /// <summary>
        /// Handles the TitlebarHeightProperty value change.
        /// </summary>
        /// <param name="sender">The DependencyObject on which the property has changed value.</param>
        /// <param name="e">Event data that is issued by any event that tracks changes to the effective value of this property.</param>
        private static void WhenTitlebarHeightChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // Check the new value
            if (e.NewValue.Equals(e.OldValue))
            {
                return;
            }

            // Get the WindowX
            var swmWnd = sender as WindowX;

            if (swmWnd == null)
            {
                return;
            }

            // Update the WindowX chrome
            var swmWndChrome = WindowChrome.GetWindowChrome(swmWnd);

            if (swmWndChrome == null)
            {
                return;
            }
            swmWndChrome.CaptionHeight = (double)e.NewValue;
            WindowChrome.SetWindowChrome(swmWnd, swmWndChrome);
        }
コード例 #7
0
ファイル: MetroWindow.cs プロジェクト: a1lic/MetroRadiance
        private static void IsCaptionBarChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var instance = d as FrameworkElement;

            if (instance == null)
            {
                return;
            }

            var window = GetWindow(instance) as MetroWindow;

            if (window == null)
            {
                return;
            }

            window.captionBar = (bool)e.NewValue ? instance : null;

            instance.Loaded += (sender, args) =>
            {
                var chrome = WindowChrome.GetWindowChrome(window);
                if (chrome != null)
                {
                    chrome.CaptionHeight = instance.ActualHeight;
                }
            };
        }
コード例 #8
0
        private void LoadedHandler(object sender, RoutedEventArgs e)
        {
            var currentWindow = sender.As <Window>();

            if (!WindowThemeParameters.GetIsResizable(currentWindow))
            {
                WindowChrome.GetWindowChrome(currentWindow).ResizeBorderThickness = default;
コード例 #9
0
        //public BaseWinTitle() : base() {
        //	//InitializeComponent();
        //	Background = Brushes.Transparent;

        //	//Loaded += BaseWinTitle_Loaded;
        //}

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            //Debug.WriteLine("aa");
            win = findWin();
            if (win == null)
            {
                //base.OnVisualParentChanged(oldParent);
                return;
            }

            win.MouseLeftButtonDown += Win_MouseLeftButtonDown;
            win.MouseLeftButtonUp   += Win_MouseLeftButtonUp;

            WindowChrome chrome = WindowChrome.GetWindowChrome(win);

            if (chrome == null)
            {
                chrome = new WindowChrome();
                chrome.CaptionHeight       = 0;
                chrome.CornerRadius        = new CornerRadius(0);
                chrome.GlassFrameThickness = new Thickness(1);
                chrome.NonClientFrameEdges = NonClientFrameEdges.None;
                //base.OnVisualParentChanged(oldParent);
                //return;
                WindowChrome.SetWindowChrome(win, chrome);
            }
            chrome.ResizeBorderThickness = oldTickness;

            // Call base class to perform standard event handling.
            //base.OnVisualParentChanged(oldParent);
        }
コード例 #10
0
ファイル: Helper.cs プロジェクト: vincent1912/wpfNotifyBox
        /// <summary>
        /// 获取元素在屏幕中的位置和大小
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static Rect GetElementBounds(FrameworkElement element)
        {
            if (element is Window win)
            {
                Thickness resizeBorderThickness   = new Thickness(0);
                Thickness nonClientFrameThickness = new Thickness(0);
                if (WindowChrome.GetWindowChrome(win) == null)
                {
                    if (win.WindowStyle != WindowStyle.None)
                    {
                        nonClientFrameThickness = SystemParameters.WindowNonClientFrameThickness;
                    }
                    if (win.ResizeMode != ResizeMode.NoResize)
                    {
                        resizeBorderThickness = SystemParameters.WindowResizeBorderThickness;
                    }
                }
                return(new Rect(
                           win.Left + resizeBorderThickness.Left + nonClientFrameThickness.Left,
                           win.Top,
                           win.ActualWidth - (resizeBorderThickness.Left + resizeBorderThickness.Right + nonClientFrameThickness.Left + nonClientFrameThickness.Right),
                           win.ActualHeight - (resizeBorderThickness.Bottom + nonClientFrameThickness.Bottom)));
            }
            Point position = element.PointToScreen(new Point(0, 0));

            return(new Rect(position.X / GetDPIRatio(), position.Y / GetDPIRatio(), element.ActualWidth, element.ActualHeight));
        }
コード例 #11
0
        //private bool isWinMax() {
        //	if (win == null) { return false; }

        //	//Window win = findWin();
        //	Rect rc = SystemParameters.WorkArea;//获取工作区大小
        //	if (win.Width == rc.Width && win.Height == rc.Height) {
        //		return true;
        //	}

        //	return false;
        //}

        public void updateWinSize()
        {
            if (win == null)
            {
                return;
            }

            //Window win = findWin();
            WindowChrome chrome = WindowChrome.GetWindowChrome(win);

            //if (isFirstRect) {

            //}

            //Grid grdNormal = (Grid)FindName("btnNormal");
            //Grid grdMax = (Grid)FindName("btnMax");
            if (isMax)
            {
                chrome.ResizeBorderThickness = oldTickness;

                win.Left   = rcNormal.Left;
                win.Top    = rcNormal.Top;
                win.Width  = rcNormal.Width;
                win.Height = rcNormal.Height;

                //grdNormal.Visibility = Visibility.Visible;
                //grdMax.Visibility = Visibility.Collapsed;
            }
            else
            {
                oldTickness = chrome.ResizeBorderThickness;
                chrome.ResizeBorderThickness = new Thickness(0);

                rcNormal = new Rect(win.Left, win.Top, win.Width, win.Height); //保存下当前位置与大小

                win.Left = 0;                                                  //设置位置
                win.Top  = 0;
                Rect rc = SystemParameters.WorkArea;                           //获取工作区大小
                win.Width  = rc.Width;
                win.Height = rc.Height;

                //grdNormal.Visibility = Visibility.Collapsed;
                //grdMax.Visibility = Visibility.Visible;
            }
            isMax       = !isMax;
            IsMaximized = isMax;
            //Debug.WriteLine(IsMaximized);
            //if (win.WindowState == WindowState.Maximized) {
            //	win.WindowState = WindowState.Normal; //设置窗口还原
            //} else {
            //	win.WindowState = WindowState.Maximized; //设置窗口最大化
            //}

            //Grid grdNormal = (Grid)FindName("btnNormal");
            //Grid grdMax = (Grid)FindName("btnMax");

            //grdNormal.Visibility = win.WindowState == WindowState.Maximized ? Visibility.Collapsed : Visibility.Visible;
            //grdMax.Visibility = win.WindowState == WindowState.Maximized ? Visibility.Visible : Visibility.Collapsed;
        }
コード例 #12
0
 private void OnInitializedInternal(object sender, EventArgs e)
 {
     if (Equals(WindowChrome.GetWindowChrome(this), _chrome) && SizeToContent != SizeToContent.Manual)
     {
         _previousSizeToContent = SizeToContent;
         SizeToContent          = SizeToContent.Manual;
     }
 }
コード例 #13
0
        private void OnTitleBarHeightChanged(double height)
        {
            var chrome = WindowChrome.GetWindowChrome(this);

            if (chrome != null)
            {
                chrome.CaptionHeight = height;
            }
        }
コード例 #14
0
        /// <summary>
        /// ResizeBorderThickness を更新します。
        /// </summary>
        private void UpdateResizeBorderThickness()
        {
            var chrome = WindowChrome.GetWindowChrome(this);

            if (chrome != null)
            {
                chrome.ResizeBorderThickness = this.ResizeMode == ResizeMode.NoResize ? new Thickness(0) : SystemParameters.WindowResizeBorderThickness;
            }
        }
コード例 #15
0
 private void _headerPanel_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (_headerElement is not null && e.HeightChanged)
     {
         var windowChrome = WindowChrome.GetWindowChrome(this);
         windowChrome.CaptionHeight = e.NewSize.Height - windowChrome.ResizeBorderThickness.Top;
         WindowChrome.SetWindowChrome(this, windowChrome);
     }
 }
コード例 #16
0
        private void UpdateWindowStateVisuals()
        {
            if (WindowState == WindowState.Maximized)
            {
                double borderWidth = 3;

                try
                {
                    ribbon.FindChild <FrameworkElement>("QatTopHost").Margin     = new Thickness(0, borderWidth, 0, -borderWidth);
                    ribbon.FindChild <FrameworkElement>("PART_TitleHost").Margin = new Thickness(0, borderWidth + 3, 0, -(borderWidth + 3));

                    RibbonContextualTabGroupItemsControl rctgic = ribbon.FindChild <RibbonContextualTabGroupItemsControl>("PART_ContextualTabGroupItemsControl");
                    rctgic.Margin = new Thickness(0, 1, 0, -2);
                    foreach (RibbonContextualTabGroup each in rctgic.InternalItemsHost.Children)
                    {
                        each.Height = 53;
                    }
                }
                catch { }

                maximizeRestoreButton.Content = FindResource("RestoreButtonKey");
                maximizeRestoreButton.ToolTip = "Restore Down";

                outerGrid.Margin        = new Thickness(SystemParameters.BorderWidth + 2, SystemParameters.BorderWidth + 1, SystemParameters.BorderWidth + 2, SystemParameters.BorderWidth + 2);
                windowBorder.Visibility = Visibility.Collapsed;
                minimizeButton.Margin   = new Thickness(0, -2, 0, 2);

                WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                chrome.ResizeBorderThickness = new Thickness(0);
            }
            else if (WindowState == WindowState.Normal)
            {
                try
                {
                    ribbon.FindChild <FrameworkElement>("QatTopHost").Margin     = new Thickness(0, 3, 0, -3);
                    ribbon.FindChild <FrameworkElement>("PART_TitleHost").Margin = new Thickness(0, 7, 0, -7);

                    RibbonContextualTabGroupItemsControl rctgic = ribbon.FindChild <RibbonContextualTabGroupItemsControl>("PART_ContextualTabGroupItemsControl");
                    rctgic.Margin = new Thickness(0, 0, 0, -2);
                    foreach (RibbonContextualTabGroup each in rctgic.InternalItemsHost.Children)
                    {
                        each.Height = 54;
                    }
                }
                catch { }

                maximizeRestoreButton.Content = FindResource("MaximizeButtonKey");
                maximizeRestoreButton.ToolTip = "Maximize";
                outerGrid.Margin        = new Thickness(0);
                windowBorder.Visibility = Visibility.Visible;
                minimizeButton.Margin   = new Thickness(0);

                WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                chrome.ResizeBorderThickness = new Thickness(1);
            }
        }
コード例 #17
0
        private void UpdateCaptionHeight()
        {
            WindowChrome chrome    = WindowChrome.GetWindowChrome(this);
            Thickness    thickness = SystemParameters.WindowResizeBorderThickness;

            if (chrome != null)
            {
                chrome.CaptionHeight = 40 - thickness.Top;
            }
        }
コード例 #18
0
        private static void DisableResizeBorder(Window window)
        {
            var chrome    = WindowChrome.GetWindowChrome(window);
            var thickness = new Thickness(0);

            // Synch the chrome resize border width
            // and the window border width
            window.BorderThickness       = thickness;
            chrome.ResizeBorderThickness = thickness;

            WindowChrome.SetWindowChrome(window, chrome);
        }
コード例 #19
0
        /// <summary>
        /// Fixes the window chrome bug.
        /// If the window chrome stays attached, the taskbar button might disappear.
        /// </summary>
        private void FixWindowChromeBug()
        {
            var mainView = View;

            var chrome = WindowChrome.GetWindowChrome(mainView);

            WindowChrome.SetWindowChrome(mainView, null);

            var setChrome = new Action <Window, WindowChrome>(WindowChrome.SetWindowChrome);

            mainView.Dispatcher.BeginInvoke(setChrome, DispatcherPriority.Render, mainView, chrome);
        }
コード例 #20
0
 internal static void SetCaptionHeight(WindowX windowX, double height)
 {
     windowX.Dispatcher.BeginInvoke(new Action(() =>
     {
         var chrome = WindowChrome.GetWindowChrome(windowX);
         if (chrome == null || double.IsNaN(height) || double.IsInfinity(height))
         {
             return;
         }
         chrome.CaptionHeight = height;
     }), System.Windows.Threading.DispatcherPriority.Loaded);
 }
コード例 #21
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            EnableBlur(this);

            if (GetTemplateChild("captionGrid") is FrameworkElement caption)
            {
                caption.SizeChanged += (s, e) => {
                    var chrome = WindowChrome.GetWindowChrome(this);
                    chrome.CaptionHeight = e.NewSize.Height;
                };
            }
        }
コード例 #22
0
        private static void EnableResizeBorder(Window window, double left, double top, double right, double bottom)
        {
            var chrome = WindowChrome.GetWindowChrome(window);

            var thickness = new Thickness(left, top, right, bottom);

            // The chrome resize border needs the actual window border to
            // be non zero otherwise it won't allow resizing
            chrome.ResizeBorderThickness = thickness;
            window.BorderThickness       = thickness;

            WindowChrome.SetWindowChrome(window, chrome);
        }
コード例 #23
0
 public new bool?ShowDialog()
 {
     if (Equals(WindowChrome.GetWindowChrome(this), _chrome) && SizeToContent != SizeToContent.Manual)
     {
         new UIPermission(PermissionState.Unrestricted).Demand();
         _dispatcherFrame = new DispatcherFrame();
         Show();
         Dispatcher.PushFrame(_dispatcherFrame);
         _dispatcherFrame = null;
         return(base.ShowDialog());
     }
     return(base.ShowDialog());
 }
コード例 #24
0
        protected override void OnStateChanged(EventArgs e)
        {
            titleBar_Maximize.Content      = WindowState == WindowState.Maximized ? "🗗": "🗖";
            titleBar_Fullscreen.Visibility = ResizeMode == ResizeMode.CanResize || WindowState != WindowState.Maximized ? Visibility.Visible : Visibility.Hidden;
            BorderThickness = new Thickness(WindowState == WindowState.Maximized ? 8 : 0);

            var windowChrome = WindowChrome.GetWindowChrome(this);

            windowChrome.GlassFrameThickness = new Thickness(WindowState == WindowState.Maximized ? 1 : 0);
            WindowChrome.SetWindowChrome(this, windowChrome);

            base.OnStateChanged(e);
        }
コード例 #25
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            FrameworkElement windowHeaderElement;

            if (Template.TryFindName(PartNameWindowHeader, this, out windowHeaderElement))
            {
                _templatePartWindowHeader = windowHeaderElement;
                var chrome = WindowChrome.GetWindowChrome(this);

                Binding captionHeightBinding = new Binding();
                captionHeightBinding.Source = windowHeaderElement;
                captionHeightBinding.Path   = new PropertyPath(nameof(FrameworkElement.ActualHeight));
                captionHeightBinding.Mode   = BindingMode.OneWay;
                captionHeightBinding.NotifyOnSourceUpdated = true;
                BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty, captionHeightBinding);
            }

            var visibilityConverter = new BooleanToVisibilityConverter();

            if (Template.TryFindName(PartNameCloseButton, this, out _templatePartButtonClose))
            {
                _templatePartButtonClose.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true);
                _templatePartButtonClose.PreviewMouseLeftButtonUp += TemplatePartButtonCloseOnMouseUp;
                _templatePartButtonClose.SetBinding(VisibilityProperty, IsCloseButtonVisibleProperty, this, visibilityConverter);
            }

            if (Template.TryFindName(PartNameMinimizeButton, this, out _templatePartButtonMinimize))
            {
                _templatePartButtonMinimize.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true);
                _templatePartButtonMinimize.PreviewMouseLeftButtonUp += TemplatePartButtonMinimizeOnMouseUp;
                _templatePartButtonMinimize.SetBinding(VisibilityProperty, IsMinimizeButtonVisibleProperty, this, visibilityConverter);
            }

            if (Template.TryFindName(PartNameMaximizeButton, this, out _templatePartButtonMaximize))
            {
                _templatePartButtonMaximize.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true);
                _templatePartButtonMaximize.PreviewMouseLeftButtonUp += TemplatePartButtonMaximizeOnMouseUp;
                _templatePartButtonMaximize.SetBinding(VisibilityProperty, IsMaximizeButtonVisibleProperty, this, visibilityConverter);
            }

            if (Template.TryFindName(PartNameRestoreButton, this, out _templatePartButtonRestore))
            {
                _templatePartButtonRestore.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true);
                _templatePartButtonRestore.PreviewMouseLeftButtonUp += TemplatePartButtonRestoreOnMouseUp;
                _templatePartButtonRestore.SetBinding(VisibilityProperty, IsRestoreButtonVisibleProperty, this, visibilityConverter);
            }

            AdjustVisibilityToWindowState();
        }
コード例 #26
0
        private void BelongWindow_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case System.Windows.Input.Key.Escape:
            {
                if (BelongWindow != null && this.FullScreen == true)
                {
                    WindowChrome.SetWindowChrome(this.BelongWindow, FullScreenWindowChrome);
                    this.BelongWindow.WindowState = FullScreenWindowState;
                    this.BelongWindow.WindowStyle = FullScreenWindowStyle;

                    this.FullScreen = false;
                }
            }
            break;

            case System.Windows.Input.Key.F11:
            {
                if (BelongWindow != null && this.FullScreen == false &&
                    BelongWindow.ResizeMode == ResizeMode.CanResize)
                {
                    FullScreenWindowChrome = WindowChrome.GetWindowChrome(this.BelongWindow);
                    FullScreenWindowStyle  = this.BelongWindow.WindowStyle;
                    FullScreenWindowState  = this.BelongWindow.WindowState;

                    //this.BelongWindow.BeginInit();
                    if (this.BelongWindow.WindowState == WindowState.Maximized)
                    {
                        this.BelongWindow.StateChanged -= BelongWindow_StateChanged;
                        this.BelongWindow.WindowState   = WindowState.Normal;
                        this.BelongWindow.StateChanged += BelongWindow_StateChanged;
                        //this.BelongWindow.Visibility = Visibility.Hidden;
                    }
                    this.BelongWindow.WindowStyle = WindowStyle.None;
                    WindowChrome.SetWindowChrome(this.BelongWindow, null);
                    this.BelongWindow.WindowState = WindowState.Maximized;
                    this.BelongWindow.Visibility  = Visibility.Visible;
                    this.BelongWindow.Focus();
                    //this.BelongWindow.EndInit();
                    //this.BelongWindow.Topmost = true;

                    this.FullScreen = true;
                }
            }
            break;

            default:
                break;
            }
        }
コード例 #27
0
        private void OnLoadedInternal(object sender, RoutedEventArgs e)
        {
            if (Equals(WindowChrome.GetWindowChrome(this), _chrome) && _previousSizeToContent != SizeToContent.Manual)
            {
                SizeToContent          = _previousSizeToContent;
                _previousSizeToContent = SizeToContent.Manual;

                if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
                {
                    Left = SystemParameters.VirtualScreenLeft + SystemParameters.PrimaryScreenWidth / 2 - ActualWidth / 2;
                    Top  = SystemParameters.VirtualScreenTop + SystemParameters.PrimaryScreenHeight / 2 - ActualHeight / 2;
                }
                if (WindowStartupLocation == WindowStartupLocation.CenterOwner)
                {
                    if (Owner != null)
                    {
                        if (Owner.WindowState == WindowState.Maximized)
                        {
                            var source = PresentationSource.FromVisual(Owner);
                            if (source != null && source.CompositionTarget != null)
                            {
                                var ownerHandle = new WindowInteropHelper(Owner).EnsureHandle();
                                var ownerWindow = new Native.Window(ownerHandle);
                                ownerWindow.Invalidate();
                                Left = -ownerWindow.NonClientBorderWidth * source.CompositionTarget.TransformFromDevice.M11;
                                Top  = -ownerWindow.NonClientBorderHeight * source.CompositionTarget.TransformFromDevice.M22;
                            }
                            else
                            {
                                Left = 0;
                                Top  = 0;
                            }
                        }
                        else
                        {
                            Left = Owner.Left;
                            Top  = Owner.Top;
                        }
                        Left += Owner.ActualWidth / 2 - ActualWidth / 2;
                        Top  += Owner.ActualHeight / 2 - ActualHeight / 2;
                    }
                }

                UpdateNonClientBorder();

                if (_dispatcherFrame != null)
                {
                    _dispatcherFrame.Continue = false;
                }
            }
        }
コード例 #28
0
        public new bool?ShowDialog()
        {
            if (Equals(WindowChrome.GetWindowChrome(this), _chrome) && SizeToContent != SizeToContent.Manual)
            {
                _dispatcherFrame = new DispatcherFrame();

                Show();

                Dispatcher.PushFrame(_dispatcherFrame);
                _dispatcherFrame = null;
                return(base.ShowDialog());
            }
            return(base.ShowDialog());
        }
コード例 #29
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case Interop.WM_GETMINMAXINFO:
                if (Equals(WindowChrome.GetWindowChrome(this), _chrome))
                {
                    GetMinMaxInfo(lParam);
                    handled = true;
                }
                break;
            }

            return((IntPtr)0);
        }
コード例 #30
0
    protected override void OnStateChanged(EventArgs e)
    {
        base.OnStateChanged(e);

        var windowChrome = WindowChrome.GetWindowChrome(this);

        windowChrome.CaptionHeight += windowChrome.ResizeBorderThickness.Top;

        if (_backgroundBorder is not null)
        {
            _backgroundBorder.Margin = WindowState == WindowState.Maximized ?
                                       Subtract(windowChrome.ResizeBorderThickness, Add(_backgroundBorder.BorderThickness, 2))
                : new Thickness(0);
        }
    }