Browse Source

fix failing unit test.

pull/1806/head
Dan Walmsley 8 years ago
parent
commit
7d28d1b2ab
  1. 23
      src/Avalonia.Controls/Primitives/PopupRoot.cs
  2. 5
      tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

23
src/Avalonia.Controls/Primitives/PopupRoot.cs

@ -83,19 +83,22 @@ namespace Avalonia.Controls.Primitives
/// </summary>
public void SnapInsideScreenEdges()
{
var screen = Application.Current.MainWindow.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));
}
}
}

5
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

@ -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
{

Loading…
Cancel
Save