private void UpdateNonClientBorder() { if (!Equals(WindowChrome.GetWindowChrome(this), _chrome) || _layoutRoot == null || _window == null) { return; } Taskbar.Invalidate(); if (WindowState == WindowState.Maximized && !Taskbar.AutoHide && SizeToContent == SizeToContent.Manual) { _window.Invalidate(); _layoutRoot.Margin = new Thickness(_window.NonClientBorderWidth, _window.NonClientBorderHeight, _window.NonClientBorderWidth, _window.NonClientBorderHeight); } else { _layoutRoot.Margin = new Thickness(); } }
private void GetMinMaxInfo(IntPtr lParam) { var info = (Interop.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Interop.MINMAXINFO)); _monitor.Invalidate(); Taskbar.Invalidate(); var bounds = _monitor.Bounds; var workArea = _monitor.WorkArea; info.ptMaxPosition.x = Math.Abs(bounds.left) + Taskbar.Position == TaskbarPosition.Left && Taskbar.AutoHide ? 1 : 0; info.ptMaxPosition.y = Math.Abs(bounds.top) + Taskbar.Position == TaskbarPosition.Top && Taskbar.AutoHide ? 1 : 0; info.ptMaxSize.x = info.ptMaxTrackSize.x = Math.Abs(workArea.right - workArea.left) - (Taskbar.Position == TaskbarPosition.Right && Taskbar.AutoHide ? 1 : 0); info.ptMaxSize.y = info.ptMaxTrackSize.y = Math.Abs(workArea.bottom - workArea.top) - (Taskbar.Position == TaskbarPosition.Bottom && Taskbar.AutoHide ? 1 : 0); var source = PresentationSource.FromVisual(this); if (source != null && source.CompositionTarget != null) { if (DoubleUtil.IsNonNegative(MinWidth)) { info.ptMinTrackSize.x = (int)Math.Ceiling(MinWidth * source.CompositionTarget.TransformFromDevice.M11); } if (DoubleUtil.IsNonNegative(MinHeight)) { info.ptMinTrackSize.y = (int)Math.Ceiling(MinHeight * source.CompositionTarget.TransformFromDevice.M22); } if (DoubleUtil.IsNonNegative(MaxWidth)) { info.ptMaxSize.x = info.ptMaxTrackSize.x = Math.Min(info.ptMaxSize.x, (int)Math.Ceiling(MaxWidth * source.CompositionTarget.TransformFromDevice.M11)); } if (DoubleUtil.IsNonNegative(MaxHeight)) { info.ptMaxSize.y = info.ptMaxTrackSize.y = Math.Min(info.ptMaxSize.y, (int)Math.Ceiling(MaxHeight * source.CompositionTarget.TransformFromDevice.M22)); } } Marshal.StructureToPtr(info, lParam, true); }