|
|
|
@ -57,10 +57,6 @@ namespace Avalonia.Controls |
|
|
|
/// </summary>
|
|
|
|
public Action<TAppBuilder> AfterSetupCallback { get; private set; } = builder => { }; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a method to call before Start is called on the <see cref="Application"/>.
|
|
|
|
/// </summary>
|
|
|
|
public Action<TAppBuilder> BeforeStartCallback { get; private set; } = builder => { }; |
|
|
|
|
|
|
|
protected AppBuilderBase(IRuntimePlatform platform, Action<TAppBuilder> platformServices) |
|
|
|
{ |
|
|
|
@ -95,17 +91,6 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
protected TAppBuilder Self => (TAppBuilder)this; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Registers a callback to call before Start is called on the <see cref="Application"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="callback">The callback.</param>
|
|
|
|
/// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns>
|
|
|
|
public TAppBuilder BeforeStarting(Action<TAppBuilder> callback) |
|
|
|
{ |
|
|
|
BeforeStartCallback = (Action<TAppBuilder>)Delegate.Combine(BeforeStartCallback, callback); |
|
|
|
return Self; |
|
|
|
} |
|
|
|
|
|
|
|
public TAppBuilder AfterSetup(Action<TAppBuilder> callback) |
|
|
|
{ |
|
|
|
AfterSetupCallback = (Action<TAppBuilder>)Delegate.Combine(AfterSetupCallback, callback); |
|
|
|
@ -121,47 +106,24 @@ namespace Avalonia.Controls |
|
|
|
public void Start<TMainWindow>(Func<object> dataContextProvider = null) |
|
|
|
where TMainWindow : Window, new() |
|
|
|
{ |
|
|
|
Setup(); |
|
|
|
BeforeStartCallback(Self); |
|
|
|
|
|
|
|
var window = new TMainWindow(); |
|
|
|
if (dataContextProvider != null) |
|
|
|
window.DataContext = dataContextProvider(); |
|
|
|
Instance.Run(window); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Starts the application with the provided instance of <typeparamref name="TMainWindow"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TMainWindow">The window type.</typeparam>
|
|
|
|
/// <param name="mainWindow">Instance of type TMainWindow to use when starting the app</param>
|
|
|
|
/// <param name="dataContextProvider">A delegate that will be called to create a data context for the window (optional).</param>
|
|
|
|
[Obsolete("Use either lifetimes or AppMain overload. See see https://github.com/AvaloniaUI/Avalonia/wiki/Application-lifetimes for details")] |
|
|
|
public void Start<TMainWindow>(TMainWindow mainWindow, Func<object> dataContextProvider = null) |
|
|
|
where TMainWindow : Window |
|
|
|
{ |
|
|
|
Setup(); |
|
|
|
BeforeStartCallback(Self); |
|
|
|
|
|
|
|
if (dataContextProvider != null) |
|
|
|
mainWindow.DataContext = dataContextProvider(); |
|
|
|
Instance.Run(mainWindow); |
|
|
|
} |
|
|
|
|
|
|
|
public delegate void AppMainDelegate(Application app, string[] args); |
|
|
|
|
|
|
|
[Obsolete("Use either lifetimes or AppMain overload. See see https://github.com/AvaloniaUI/Avalonia/wiki/Application-lifetimes for details")] |
|
|
|
public void Start() |
|
|
|
{ |
|
|
|
Setup(); |
|
|
|
BeforeStartCallback(Self); |
|
|
|
Instance.Run(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Start(AppMainDelegate main, string[] args) |
|
|
|
{ |
|
|
|
Setup(); |
|
|
|
BeforeStartCallback(Self); |
|
|
|
main(Instance, args); |
|
|
|
} |
|
|
|
|
|
|
|
|