Browse Source
Merge pull request #1806 from AvaloniaUI/fix-popup-root-exception
fixes an occasional crash with popup root "SnapInsideScreenEdges"
pull/1808/head
danwalmsley
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
17 additions and
13 deletions
-
src/Avalonia.Controls/Primitives/PopupRoot.cs
-
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
|
|
|
@ -83,21 +83,22 @@ namespace Avalonia.Controls.Primitives |
|
|
|
/// </summary>
|
|
|
|
public void SnapInsideScreenEdges() |
|
|
|
{ |
|
|
|
var window = this.GetSelfAndLogicalAncestors().OfType<Window>().First(); |
|
|
|
|
|
|
|
var screen = window.Screens.ScreenFromPoint(Position); |
|
|
|
var screen = Application.Current.MainWindow?.Screens.ScreenFromPoint(Position); |
|
|
|
|
|
|
|
var screenX = Position.X + Bounds.Width - screen.Bounds.X; |
|
|
|
var screenY = Position.Y + Bounds.Height - screen.Bounds.Y; |
|
|
|
|
|
|
|
if (screenX > screen.Bounds.Width) |
|
|
|
if (screen != null) |
|
|
|
{ |
|
|
|
Position = Position.WithX(Position.X - (screenX - screen.Bounds.Width)); |
|
|
|
} |
|
|
|
var screenX = Position.X + Bounds.Width - screen.Bounds.X; |
|
|
|
var screenY = Position.Y + Bounds.Height - screen.Bounds.Y; |
|
|
|
|
|
|
|
if (screenY > screen.Bounds.Height) |
|
|
|
{ |
|
|
|
Position = Position.WithY(Position.Y - (screenY - screen.Bounds.Height)); |
|
|
|
if (screenX > screen.Bounds.Width) |
|
|
|
{ |
|
|
|
Position = Position.WithX(Position.X - (screenX - screen.Bounds.Width)); |
|
|
|
} |
|
|
|
|
|
|
|
if (screenY > screen.Bounds.Height) |
|
|
|
{ |
|
|
|
Position = Position.WithY(Position.Y - (screenY - screen.Bounds.Height)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +64,10 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
{ |
|
|
|
ContextMenu = sut |
|
|
|
}; |
|
|
|
new Window { Content = target }; |
|
|
|
|
|
|
|
var window = new Window { Content = target }; |
|
|
|
|
|
|
|
Avalonia.Application.Current.MainWindow = window; |
|
|
|
|
|
|
|
target.RaiseEvent(new PointerReleasedEventArgs |
|
|
|
{ |
|
|
|
|