Browse Source

Designer: Fixes for scroll and crash

pull/148/head
Nikita Tsukanov 11 years ago
parent
commit
d48c5ac3b0
  1. 24
      src/Windows/Perspex.Designer/AppHost/WindowHost.cs
  2. 3
      src/Windows/Perspex.Designer/PerspexDesigner.xaml.cs

24
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();
}
}

3
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)
{

Loading…
Cancel
Save