Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unnecessary window displacement on resize #18004

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion samples/IntegrationTestApp/ShowWindowTest.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
<Label Grid.Row="11" Content="MeasuredWith:" />
<TextBlock Grid.Column="1" Grid.Row="11" Name="CurrentMeasuredWithText" Text="{Binding #MyBorder.MeasuredWith}" />

<Button Name="HideButton" Grid.Row="12" Command="{Binding $parent[Window].Hide}">Hide</Button>
<StackPanel Orientation="Horizontal" Grid.Row="12">
<Button Name="HideButton" Command="{Binding $parent[Window].Hide}">Hide</Button>
<Button Name="AddToWidth" Click="AddToWidth_Click">Add to Width</Button>
<Button Name="AddToHeight" Click="AddToHeight_Click">Add to Height</Button>
</StackPanel>

</Grid>
</integrationTestApp:MeasureBorder>
Expand Down
4 changes: 4 additions & 0 deletions samples/IntegrationTestApp/ShowWindowTest.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;

namespace IntegrationTestApp
Expand Down Expand Up @@ -70,5 +71,8 @@ private void TimerOnTick(object? sender, EventArgs e)
{
_orderTextBox!.Text = MacOSIntegration.GetOrderedIndex(this).ToString();
}

private void AddToWidth_Click(object? sender, RoutedEventArgs e) => Width += 10;
private void AddToHeight_Click(object? sender, RoutedEventArgs e) => Height += 10;
}
}
6 changes: 0 additions & 6 deletions src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,6 @@ public void Resize(Size value, WindowResizeReason reason)
return;
}
}
else
{
var position = Position;
windowPlacement.NormalPosition.left = position.X;
windowPlacement.NormalPosition.top = position.Y;
}

windowPlacement.NormalPosition.right = windowPlacement.NormalPosition.left + windowWidth;
windowPlacement.NormalPosition.bottom = windowPlacement.NormalPosition.top + windowHeight;
Expand Down
18 changes: 18 additions & 0 deletions tests/Avalonia.IntegrationTests.Appium/WindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ public void Changing_WindowState_Should_Not_Change_Frame_Size_And_Position()
}
}

[PlatformFact(TestPlatforms.Windows)]
public void Changing_Size_Should_Not_Change_Position()
{
using (OpenWindow())
{
var info = GetWindowInfo();

Session.FindElementByAccessibilityId("AddToWidth").SendClick();
Session.FindElementByAccessibilityId("AddToHeight").SendClick();

var updatedInfo = GetWindowInfo();
Assert.Equal(info.Position, updatedInfo.Position);
Assert.Equal(info.FrameSize
.WithWidth(info.FrameSize.Width + 10)
.WithHeight(info.FrameSize.Height + 10), updatedInfo.FrameSize);
}
}

public static TheoryData<Size?, ShowWindowMode, WindowStartupLocation, bool> StartupLocationData()
{
var sizes = new Size?[] { null, new Size(400, 300) };
Expand Down
Loading