Browse Source

Add Window IsDialog Property (#19226)

Co-authored-by: Sebastian Redinger <sebastian.redinger@chaos.com>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
release/11.3.4
davisx2 1 year ago
committed by Julien Lebosquain
parent
commit
b6b3c4ec2f
  1. 17
      src/Avalonia.Controls/Window.cs

17
src/Avalonia.Controls/Window.cs

@ -481,6 +481,11 @@ namespace Avalonia.Controls
} }
} }
/// <summary>
/// Gets whether this window was opened as a dialog
/// </summary>
public bool IsDialog => _showingAsDialog;
/// <summary> /// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler /// Starts moving a window with left button being held. Should be called from left mouse button press event handler
/// </summary> /// </summary>
@ -761,12 +766,12 @@ namespace Avalonia.Controls
return null; return null;
} }
_showingAsDialog = modal;
RaiseEvent(new RoutedEventArgs(WindowOpenedEvent)); RaiseEvent(new RoutedEventArgs(WindowOpenedEvent));
EnsureInitialized(); EnsureInitialized();
ApplyStyling(); ApplyStyling();
_shown = true; _shown = true;
_showingAsDialog = modal;
IsVisible = true; IsVisible = true;
// If window position was not set before then platform may provide incorrect scaling at this time, // If window position was not set before then platform may provide incorrect scaling at this time,
@ -984,7 +989,7 @@ namespace Avalonia.Controls
{ {
return; return;
} }
var location = GetEffectiveWindowStartupLocation(owner); var location = GetEffectiveWindowStartupLocation(owner);
switch (location) switch (location)
@ -1017,7 +1022,7 @@ namespace Avalonia.Controls
return startupLocation; return startupLocation;
} }
private void SetWindowStartupLocation(Window? owner = null) private void SetWindowStartupLocation(Window? owner = null)
{ {
if (_wasShownBefore) if (_wasShownBefore)
@ -1052,7 +1057,7 @@ namespace Avalonia.Controls
screen ??= Screens.ScreenFromPoint(Position); screen ??= Screens.ScreenFromPoint(Position);
screen ??= Screens.Primary; screen ??= Screens.Primary;
if (screen is not null) if (screen is not null)
{ {
var childRect = screen.WorkingArea.CenterRect(rect); var childRect = screen.WorkingArea.CenterRect(rect);
@ -1072,7 +1077,7 @@ namespace Avalonia.Controls
var childRect = ownerRect.CenterRect(rect); var childRect = ownerRect.CenterRect(rect);
var screen = Screens.ScreenFromWindow(owner); var screen = Screens.ScreenFromWindow(owner);
childRect = ApplyScreenConstraint(screen, childRect); childRect = ApplyScreenConstraint(screen, childRect);
Position = childRect.Position; Position = childRect.Position;
@ -1080,7 +1085,7 @@ namespace Avalonia.Controls
if (!_positionWasSet && DesktopScaling != PlatformImpl?.DesktopScaling) // Platform returns incorrect scaling, forcing setting position may fix it if (!_positionWasSet && DesktopScaling != PlatformImpl?.DesktopScaling) // Platform returns incorrect scaling, forcing setting position may fix it
PlatformImpl?.Move(Position); PlatformImpl?.Move(Position);
PixelRect ApplyScreenConstraint(Screen? screen, PixelRect childRect) PixelRect ApplyScreenConstraint(Screen? screen, PixelRect childRect)
{ {
if (screen?.WorkingArea is { } constraint) if (screen?.WorkingArea is { } constraint)

Loading…
Cancel
Save