Browse Source

Added TopLevel.Opened event.

And raise the event when a window is opened.
pull/2266/head
Steven Kirk 8 years ago
parent
commit
81846e87ec
  1. 11
      src/Avalonia.Controls/TopLevel.cs
  2. 2
      src/Avalonia.Controls/Window.cs
  3. 3
      src/Avalonia.Controls/WindowBase.cs

11
src/Avalonia.Controls/TopLevel.cs

@ -136,6 +136,11 @@ namespace Avalonia.Controls
} }
} }
/// <summary>
/// Fired when the window is opened.
/// </summary>
public event EventHandler Opened;
/// <summary> /// <summary>
/// Fired when the window is closed. /// Fired when the window is closed.
/// </summary> /// </summary>
@ -311,6 +316,12 @@ namespace Avalonia.Controls
$"Control '{GetType().Name}' is a top level control and cannot be added as a child."); $"Control '{GetType().Name}' is a top level control and cannot be added as a child.");
} }
/// <summary>
/// Raises the <see cref="Opened"/> event.
/// </summary>
/// <param name="e">The event args.</param>
protected virtual void OnOpened(EventArgs e) => Opened?.Invoke(this, e);
/// <summary> /// <summary>
/// Tries to get a service from an <see cref="IAvaloniaDependencyResolver"/>, logging a /// Tries to get a service from an <see cref="IAvaloniaDependencyResolver"/>, logging a
/// warning if not found. /// warning if not found.

2
src/Avalonia.Controls/Window.cs

@ -389,6 +389,7 @@ namespace Avalonia.Controls
Renderer?.Start(); Renderer?.Start();
} }
SetWindowStartupLocation(Owner?.PlatformImpl); SetWindowStartupLocation(Owner?.PlatformImpl);
OnOpened(EventArgs.Empty);
} }
/// <summary> /// <summary>
@ -458,6 +459,7 @@ namespace Avalonia.Controls
owner.Activate(); owner.Activate();
result.SetResult((TResult)(_dialogResult ?? default(TResult))); result.SetResult((TResult)(_dialogResult ?? default(TResult)));
}); });
OnOpened(EventArgs.Empty);
} }
SetWindowStartupLocation(owner); SetWindowStartupLocation(owner);

3
src/Avalonia.Controls/WindowBase.cs

@ -163,7 +163,7 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Shows the popup. /// Shows the window.
/// </summary> /// </summary>
public virtual void Show() public virtual void Show()
{ {
@ -181,6 +181,7 @@ namespace Avalonia.Controls
} }
PlatformImpl?.Show(); PlatformImpl?.Show();
Renderer?.Start(); Renderer?.Start();
OnOpened(EventArgs.Empty);
} }
finally finally
{ {

Loading…
Cancel
Save