|
|
@ -32,7 +32,7 @@ namespace Perspex |
|
|
/// method.
|
|
|
/// method.
|
|
|
/// - Tracks the lifetime of the application.
|
|
|
/// - Tracks the lifetime of the application.
|
|
|
/// </remarks>
|
|
|
/// </remarks>
|
|
|
public class Application : IGlobalDataTemplates, IGlobalStyles, IStyleRoot |
|
|
public class Application : IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IApplicationLifecycle |
|
|
{ |
|
|
{ |
|
|
static Action _platformInitializationCallback; |
|
|
static Action _platformInitializationCallback; |
|
|
|
|
|
|
|
|
@ -60,6 +60,7 @@ namespace Perspex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PerspexLocator.CurrentMutable.BindToSelf(this); |
|
|
PerspexLocator.CurrentMutable.BindToSelf(this); |
|
|
|
|
|
OnExit += OnExiting; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -146,10 +147,35 @@ namespace Perspex |
|
|
public void Run(ICloseable closable) |
|
|
public void Run(ICloseable closable) |
|
|
{ |
|
|
{ |
|
|
var source = new CancellationTokenSource(); |
|
|
var source = new CancellationTokenSource(); |
|
|
|
|
|
closable.Closed += OnExiting; |
|
|
closable.Closed += (s, e) => source.Cancel(); |
|
|
closable.Closed += (s, e) => source.Cancel(); |
|
|
Dispatcher.UIThread.MainLoop(source.Token); |
|
|
Dispatcher.UIThread.MainLoop(source.Token); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Exits the application
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Exit() |
|
|
|
|
|
{ |
|
|
|
|
|
OnExit?.Invoke(this, EventArgs.Empty); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sent when the application is exiting.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public event EventHandler OnExit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Called when the application is exiting.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected virtual void OnExiting(object sender, EventArgs e) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Register's the services needed by Perspex.
|
|
|
/// Register's the services needed by Perspex.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -168,7 +194,8 @@ namespace Perspex |
|
|
.Bind<IKeyboardNavigationHandler>().ToTransient<KeyboardNavigationHandler>() |
|
|
.Bind<IKeyboardNavigationHandler>().ToTransient<KeyboardNavigationHandler>() |
|
|
.Bind<IStyler>().ToConstant(_styler) |
|
|
.Bind<IStyler>().ToConstant(_styler) |
|
|
.Bind<ILayoutManager>().ToTransient<LayoutManager>() |
|
|
.Bind<ILayoutManager>().ToTransient<LayoutManager>() |
|
|
.Bind<IRenderQueueManager>().ToTransient<RenderQueueManager>(); |
|
|
.Bind<IRenderQueueManager>().ToTransient<RenderQueueManager>() |
|
|
|
|
|
.Bind<IApplicationLifecycle>().ToConstant(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
|