Skip to content
Merged
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
12 changes: 7 additions & 5 deletions src/ManagedShell.AppBar/AppBarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,14 @@ public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarE

// check if new coords
bool isSameCoords = false;
Rect currentRect;
GetWindowRect(abWindow.Handle, out currentRect);
if (!isCreate)
{
bool topUnchanged = abd.rc.Top == Math.Round(abWindow.Top * abWindow.DpiScale);
bool leftUnchanged = abd.rc.Left == Math.Round(abWindow.Left * abWindow.DpiScale);
bool bottomUnchanged = abd.rc.Bottom == Math.Round((abWindow.Top * abWindow.DpiScale) + (abWindow.ActualHeight * abWindow.DpiScale));
bool rightUnchanged = abd.rc.Right == Math.Round((abWindow.Left * abWindow.DpiScale) + (abWindow.ActualWidth * abWindow.DpiScale));
bool topUnchanged = abd.rc.Top == currentRect.Top;
bool leftUnchanged = abd.rc.Left == currentRect.Left;
bool bottomUnchanged = abd.rc.Bottom == currentRect.Bottom;
bool rightUnchanged = abd.rc.Right == currentRect.Right;

isSameCoords = topUnchanged
&& leftUnchanged
Expand All @@ -417,7 +419,7 @@ public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarE

if (!isSameCoords)
{
ShellLogger.Debug($"AppBarManager: {abWindow.Name} changing position (TxLxBxR) to {abd.rc.Top}x{abd.rc.Left}x{abd.rc.Bottom}x{abd.rc.Right} from {abWindow.Top * abWindow.DpiScale}x{abWindow.Left * abWindow.DpiScale}x{Math.Round((abWindow.Top * abWindow.DpiScale) + (abWindow.ActualHeight * abWindow.DpiScale))}x{Math.Round((abWindow.Left * abWindow.DpiScale) + (abWindow.ActualWidth * abWindow.DpiScale))}");
ShellLogger.Debug($"AppBarManager: {abWindow.Name} changing position (TxLxBxR) to {abd.rc.Top}x{abd.rc.Left}x{abd.rc.Bottom}x{abd.rc.Right} from {currentRect.Top}x{currentRect.Left}x{currentRect.Bottom}x{currentRect.Right}");
abWindow.SetAppBarPosition(abd.rc);
}

Expand Down
4 changes: 3 additions & 1 deletion src/ManagedShell.AppBar/AppBarWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public double DpiScale

// AppBar properties
private int AppBarMessageId = -1;
private NativeMethods.Rect _lastAppBarRect;

private AppBarEdge _appBarEdge;
public AppBarEdge AppBarEdge
Expand Down Expand Up @@ -667,13 +668,14 @@ protected void UnregisterAppBar()
#region Virtual methods
public virtual void AfterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
{
_lastAppBarRect = rect;
if (!isSameCoords)
{
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.1) };
timer.Tick += (sender1, args) =>
{
// set position again, since WPF may have overridden the original change from AppBarHelper
SetAppBarPosition(rect);
SetAppBarPosition(_lastAppBarRect);

timer.Stop();
};
Expand Down