From d48c5ac3b02cfbbe55a095c4362531f9747de084 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Sat, 19 Sep 2015 00:31:33 +0300 Subject: [PATCH] Designer: Fixes for scroll and crash --- .../Perspex.Designer/AppHost/WindowHost.cs | 24 ++++++++++++------- .../Perspex.Designer/PerspexDesigner.xaml.cs | 3 ++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Windows/Perspex.Designer/AppHost/WindowHost.cs b/src/Windows/Perspex.Designer/AppHost/WindowHost.cs index 1c377b6404..549e8a3e79 100644 --- a/src/Windows/Perspex.Designer/AppHost/WindowHost.cs +++ b/src/Windows/Perspex.Designer/AppHost/WindowHost.cs @@ -45,12 +45,18 @@ namespace Perspex.Designer.AppHost void FixPosition() { - AutoScrollMinSize = new Size(_desiredWidth, _desiredHeight); + var newScrollSize = new Size(_desiredWidth, _desiredHeight); + if (AutoScrollMinSize != newScrollSize) + AutoScrollMinSize = newScrollSize; + var width = Width - AutoScrollMargin.Width; var height = Height - AutoScrollMargin.Height; var x = Math.Max(0, (width - _windowHost.Width)/2); var y = Math.Max(0, (height - _windowHost.Height)/2); - _windowHost.Location = new Point(x, y); + + var newLoc = new Point(x - HorizontalScroll.Value, y - VerticalScroll.Value); + if(_windowHost.Location != newLoc) + _windowHost.Location = newLoc; } protected override void Dispose(bool disposing) @@ -83,14 +89,14 @@ namespace Perspex.Designer.AppHost _desiredWidth = rc.Right - rc.Left; _desiredHeight = rc.Bottom - rc.Top; var pt = _windowHost.PointToClient(new Point(rc.Left, rc.Top)); - - if (pt.Y == 0 && pt.X == 0 && _desiredWidth == _windowHost.Width && _desiredHeight == _windowHost.Height) - return; - _windowHost.Width = _desiredWidth; - _windowHost.Height = _desiredHeight; - WinApi.MoveWindow(_hWnd, 0, 0, _desiredWidth, _desiredHeight, true); - FixPosition(); + if (!(pt.Y == 0 && pt.X == 0 && _desiredWidth == _windowHost.Width && _desiredHeight == _windowHost.Height)) + { + _windowHost.Width = _desiredWidth; + _windowHost.Height = _desiredHeight; + WinApi.MoveWindow(_hWnd, 0, 0, _desiredWidth, _desiredHeight, true); + } + FixPosition(); } } diff --git a/src/Windows/Perspex.Designer/PerspexDesigner.xaml.cs b/src/Windows/Perspex.Designer/PerspexDesigner.xaml.cs index f5f6d85b0d..f5f45ef835 100644 --- a/src/Windows/Perspex.Designer/PerspexDesigner.xaml.cs +++ b/src/Windows/Perspex.Designer/PerspexDesigner.xaml.cs @@ -75,8 +75,9 @@ namespace Perspex.Designer { if (NativeContainer.Content != null) { - ((WindowHost)((WindowsFormsHost)NativeContainer.Content).Child).Dispose(); + var wndHost = ((HwndHost) NativeContainer.Content); NativeContainer.Content = null; + wndHost?.Dispose(); } if (_host.WindowHandle != IntPtr.Zero) {