Skip to content

Commit

Permalink
Fixed dragging a window out of maximized state
Browse files Browse the repository at this point in the history
  • Loading branch information
macabrett committed Oct 24, 2023
1 parent f1f4cf9 commit f01ba2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions AvaloniaEx/Views/Dialogs/BaseDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CanResize="True"
ExtendClientAreaToDecorationsHint="True"
WindowStartupLocation="CenterOwner"
PositionChanged="WindowBase_OnPositionChanged"
Background="{StaticResource SystemAltHighColor}">
<Window.Template>
<ControlTemplate>
Expand Down
14 changes: 5 additions & 9 deletions AvaloniaEx/Views/Dialogs/BaseDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Macabresoft.AvaloniaEx;

using System;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -99,21 +98,18 @@ private void TitleBar_OnDoubleTapped(object _, TappedEventArgs e) {
}

private void TitleBar_OnPointerPressed(object _, PointerPressedEventArgs e) {
if (this.WindowState != WindowState.Normal && !this._isHandlingMaximize) {
this.BeginMoveDrag(e);
}

private void WindowBase_OnPositionChanged(object _, PixelPointEventArgs e) {
if (this.WindowState == WindowState.Maximized && !this._isHandlingMaximize) {
try {
this._isHandlingMaximize = true;
var position = this.Position;
this.WindowState = WindowState.Normal;
this.Position = position;
var mousePosition = e.GetPosition(null);
var x = (int)Math.Floor(this.Position.X + mousePosition.X);
this.Position = new PixelPoint(x, position.Y);
}
finally {
this._isHandlingMaximize = false;
}
}

this.BeginMoveDrag(e);
}
}

0 comments on commit f01ba2d

Please sign in to comment.