Skip to content

Commit c9425e8

Browse files
authored
Merge pull request #124 from cairoshell/appbar-fixes
AppBar fixes
2 parents 7306747 + 087bbee commit c9425e8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/ManagedShell.AppBar/AppBarManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,14 @@ public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarE
402402

403403
// check if new coords
404404
bool isSameCoords = false;
405+
Rect currentRect;
406+
GetWindowRect(abWindow.Handle, out currentRect);
405407
if (!isCreate)
406408
{
407-
bool topUnchanged = abd.rc.Top == Math.Round(abWindow.Top * abWindow.DpiScale);
408-
bool leftUnchanged = abd.rc.Left == Math.Round(abWindow.Left * abWindow.DpiScale);
409-
bool bottomUnchanged = abd.rc.Bottom == Math.Round((abWindow.Top * abWindow.DpiScale) + (abWindow.ActualHeight * abWindow.DpiScale));
410-
bool rightUnchanged = abd.rc.Right == Math.Round((abWindow.Left * abWindow.DpiScale) + (abWindow.ActualWidth * abWindow.DpiScale));
409+
bool topUnchanged = abd.rc.Top == currentRect.Top;
410+
bool leftUnchanged = abd.rc.Left == currentRect.Left;
411+
bool bottomUnchanged = abd.rc.Bottom == currentRect.Bottom;
412+
bool rightUnchanged = abd.rc.Right == currentRect.Right;
411413

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

418420
if (!isSameCoords)
419421
{
420-
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))}");
422+
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}");
421423
abWindow.SetAppBarPosition(abd.rc);
422424
}
423425

src/ManagedShell.AppBar/AppBarWindow.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public double DpiScale
5353

5454
// AppBar properties
5555
private int AppBarMessageId = -1;
56+
private NativeMethods.Rect _lastAppBarRect;
5657

5758
private AppBarEdge _appBarEdge;
5859
public AppBarEdge AppBarEdge
@@ -667,13 +668,14 @@ protected void UnregisterAppBar()
667668
#region Virtual methods
668669
public virtual void AfterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
669670
{
671+
_lastAppBarRect = rect;
670672
if (!isSameCoords)
671673
{
672674
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.1) };
673675
timer.Tick += (sender1, args) =>
674676
{
675677
// set position again, since WPF may have overridden the original change from AppBarHelper
676-
SetAppBarPosition(rect);
678+
SetAppBarPosition(_lastAppBarRect);
677679

678680
timer.Stop();
679681
};

0 commit comments

Comments
 (0)