|
|
@ -42,9 +42,11 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
private bool _hasExecutedInitialLayoutPass; |
|
|
private bool _hasExecutedInitialLayoutPass; |
|
|
private bool _isActive; |
|
|
private bool _isActive; |
|
|
protected bool IgnoreVisibilityChange { get; set; } |
|
|
private int _ignoreVisibilityChanges; |
|
|
private WindowBase? _owner; |
|
|
private WindowBase? _owner; |
|
|
|
|
|
|
|
|
|
|
|
protected bool IgnoreVisibilityChanges => _ignoreVisibilityChanges > 0; |
|
|
|
|
|
|
|
|
static WindowBase() |
|
|
static WindowBase() |
|
|
{ |
|
|
{ |
|
|
IsVisibleProperty.OverrideDefaultValue<WindowBase>(false); |
|
|
IsVisibleProperty.OverrideDefaultValue<WindowBase>(false); |
|
|
@ -66,6 +68,11 @@ namespace Avalonia.Controls |
|
|
impl.PositionChanged = HandlePositionChanged; |
|
|
impl.PositionChanged = HandlePositionChanged; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected IDisposable FreezeVisibilityChangeHandling() |
|
|
|
|
|
{ |
|
|
|
|
|
return new IgnoreVisibilityChangesDisposable(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Fired when the window is activated.
|
|
|
/// Fired when the window is activated.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -125,18 +132,12 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public virtual void Hide() |
|
|
public virtual void Hide() |
|
|
{ |
|
|
{ |
|
|
IgnoreVisibilityChange = true; |
|
|
using (FreezeVisibilityChangeHandling()) |
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
{ |
|
|
Renderer?.Stop(); |
|
|
Renderer?.Stop(); |
|
|
PlatformImpl?.Hide(); |
|
|
PlatformImpl?.Hide(); |
|
|
IsVisible = false; |
|
|
IsVisible = false; |
|
|
} |
|
|
} |
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
IgnoreVisibilityChange = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -144,9 +145,7 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public virtual void Show() |
|
|
public virtual void Show() |
|
|
{ |
|
|
{ |
|
|
IgnoreVisibilityChange = true; |
|
|
using (FreezeVisibilityChangeHandling()) |
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
{ |
|
|
EnsureInitialized(); |
|
|
EnsureInitialized(); |
|
|
ApplyStyling(); |
|
|
ApplyStyling(); |
|
|
@ -157,14 +156,11 @@ namespace Avalonia.Controls |
|
|
LayoutManager.ExecuteInitialLayoutPass(); |
|
|
LayoutManager.ExecuteInitialLayoutPass(); |
|
|
_hasExecutedInitialLayoutPass = true; |
|
|
_hasExecutedInitialLayoutPass = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PlatformImpl?.Show(true, false); |
|
|
PlatformImpl?.Show(true, false); |
|
|
Renderer?.Start(); |
|
|
Renderer?.Start(); |
|
|
OnOpened(EventArgs.Empty); |
|
|
OnOpened(EventArgs.Empty); |
|
|
} |
|
|
} |
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
IgnoreVisibilityChange = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -202,23 +198,17 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
protected override void HandleClosed() |
|
|
protected override void HandleClosed() |
|
|
{ |
|
|
{ |
|
|
IgnoreVisibilityChange = true; |
|
|
using (FreezeVisibilityChangeHandling()) |
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
{ |
|
|
IsVisible = false; |
|
|
IsVisible = false; |
|
|
|
|
|
|
|
|
if (this is IFocusScope scope) |
|
|
if (this is IFocusScope scope) |
|
|
{ |
|
|
{ |
|
|
FocusManager.Instance?.RemoveFocusScope(scope); |
|
|
FocusManager.Instance?.RemoveFocusScope(scope); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
base.HandleClosed(); |
|
|
base.HandleClosed(); |
|
|
} |
|
|
} |
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
IgnoreVisibilityChange = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -320,7 +310,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
protected virtual void IsVisibleChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
protected virtual void IsVisibleChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
{ |
|
|
{ |
|
|
if (!IgnoreVisibilityChange) |
|
|
if (_ignoreVisibilityChanges == 0) |
|
|
{ |
|
|
{ |
|
|
if ((bool)e.NewValue!) |
|
|
if ((bool)e.NewValue!) |
|
|
{ |
|
|
{ |
|
|
@ -332,5 +322,21 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private readonly struct IgnoreVisibilityChangesDisposable : IDisposable |
|
|
|
|
|
{ |
|
|
|
|
|
private readonly WindowBase _windowBase; |
|
|
|
|
|
|
|
|
|
|
|
public IgnoreVisibilityChangesDisposable(WindowBase windowBase) |
|
|
|
|
|
{ |
|
|
|
|
|
_windowBase = windowBase; |
|
|
|
|
|
_windowBase._ignoreVisibilityChanges++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
|
{ |
|
|
|
|
|
_windowBase._ignoreVisibilityChanges--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|