Single file minimum F# Avalonia UI app.
After some experimentation, a minimum Avalonia app that can be ran from an .fsx
file or a Polyglot Notebook.
The Polyglot Notebook can be found at:
https://github.com/Fxplorer/Fxplorer_www/blob/main/docs/MinimumFsharpAvaloniaApp.ipynb
The .fsx
script can be found at:
https://fxplorer.github.io/Fxplorer_www/MinimumFsharpAvaloniaApp.fsx
#if INTERACTIVE
#r "nuget: Avalonia"
#r "nuget: Avalonia.Desktop"
#r "nuget: Avalonia.Themes.Simple"
#endif
open Avalonia
open Avalonia.Controls
let view1 () =
Window(Title = "Hello World App", Content = "Hello World from Avalonia F#!")
type App() =
inherit Application()
override this.Initialize() =
this.Styles.Add ( Avalonia.Themes.Simple.SimpleTheme() )
override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime as desktop ->
desktop.MainWindow <- view1()
printfn "Avalonia app running..."
| _ -> ()
let app =
AppBuilder.Configure<App>()
.UsePlatformDetect()
.StartWithClassicDesktopLifetime([||])
namespace Avalonia
namespace Avalonia.Controls
val view1: unit -> Window
Multiple items
type Window = inherit WindowBase interface IFocusScope interface ILayoutRoot new: unit -> unit + 1 overload member BeginMoveDrag: e: PointerPressedEventArgs -> unit member BeginResizeDrag: edge: WindowEdge * e: PointerPressedEventArgs -> unit member Close: unit -> unit + 1 overload member Hide: unit -> unit member Show: unit -> unit + 1 overload member ShowDialog: owner: Window -> Task + 1 overload ...
<summary> A top-level window. </summary>
--------------------
Window() : Window
Window(impl: Platform.IWindowImpl) : Window
type Window = inherit WindowBase interface IFocusScope interface ILayoutRoot new: unit -> unit + 1 overload member BeginMoveDrag: e: PointerPressedEventArgs -> unit member BeginResizeDrag: edge: WindowEdge * e: PointerPressedEventArgs -> unit member Close: unit -> unit + 1 overload member Hide: unit -> unit member Show: unit -> unit + 1 overload member ShowDialog: owner: Window -> Task + 1 overload ...
<summary> A top-level window. </summary>
--------------------
Window() : Window
Window(impl: Platform.IWindowImpl) : Window
Multiple items
type App = inherit Application new: unit -> App override Initialize: unit -> unit override OnFrameworkInitializationCompleted: unit -> unit
--------------------
new: unit -> App
type App = inherit Application new: unit -> App override Initialize: unit -> unit override OnFrameworkInitializationCompleted: unit -> unit
--------------------
new: unit -> App
Multiple items
type Application = inherit AvaloniaObject interface IDataContextProvider interface IGlobalDataTemplates interface IDataTemplateHost interface IGlobalStyles interface IStyleHost interface IThemeVariantHost interface IResourceHost interface IResourceNode interface IApplicationPlatformEvents ...
<summary> Encapsulates a Avalonia application. </summary>
<remarks> The <see cref="T:Avalonia.Application" /> class encapsulates Avalonia application-specific functionality, including: - A global set of <see cref="P:Avalonia.Application.DataTemplates" />. - A global set of <see cref="P:Avalonia.Application.Styles" />. - A <see cref="T:Avalonia.Input.FocusManager" />. - An <see cref="P:Avalonia.Application.InputManager" />. - Registers services needed by the rest of Avalonia in the <see cref="M:Avalonia.Application.RegisterServices" /> method. - Tracks the lifetime of the application. </remarks>
--------------------
Application() : Application
type Application = inherit AvaloniaObject interface IDataContextProvider interface IGlobalDataTemplates interface IDataTemplateHost interface IGlobalStyles interface IStyleHost interface IThemeVariantHost interface IResourceHost interface IResourceNode interface IApplicationPlatformEvents ...
<summary> Encapsulates a Avalonia application. </summary>
<remarks> The <see cref="T:Avalonia.Application" /> class encapsulates Avalonia application-specific functionality, including: - A global set of <see cref="P:Avalonia.Application.DataTemplates" />. - A global set of <see cref="P:Avalonia.Application.Styles" />. - A <see cref="T:Avalonia.Input.FocusManager" />. - An <see cref="P:Avalonia.Application.InputManager" />. - Registers services needed by the rest of Avalonia in the <see cref="M:Avalonia.Application.RegisterServices" /> method. - Tracks the lifetime of the application. </remarks>
--------------------
Application() : Application
val this: App
property Application.Styles: Styling.Styles with get
<summary> Gets the application's global styles. </summary>
<value> The application's global styles. </value>
<remarks> Global styles apply to all windows in the application. </remarks>
<summary> Gets the application's global styles. </summary>
<value> The application's global styles. </value>
<remarks> Global styles apply to all windows in the application. </remarks>
Styling.Styles.Add(item: Styling.IStyle) : unit
namespace Avalonia.Themes
namespace Avalonia.Themes.Simple
Multiple items
type SimpleTheme = inherit Styles new: ?sp: IServiceProvider -> unit
--------------------
Themes.Simple.SimpleTheme(?sp: System.IServiceProvider) : Themes.Simple.SimpleTheme
type SimpleTheme = inherit Styles new: ?sp: IServiceProvider -> unit
--------------------
Themes.Simple.SimpleTheme(?sp: System.IServiceProvider) : Themes.Simple.SimpleTheme
property Application.ApplicationLifetime: ApplicationLifetimes.IApplicationLifetime with get, set
<summary> Application lifetime, use it for things like setting the main window and exiting the app from code Currently supported lifetimes are: - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.ISingleViewApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IControlledApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IActivatableApplicationLifetime" /></summary>
<summary> Application lifetime, use it for things like setting the main window and exiting the app from code Currently supported lifetimes are: - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.ISingleViewApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IControlledApplicationLifetime" /> - <see cref="T:Avalonia.Controls.ApplicationLifetimes.IActivatableApplicationLifetime" /></summary>
namespace Avalonia.Controls.ApplicationLifetimes
type IClassicDesktopStyleApplicationLifetime =
inherit IControlledApplicationLifetime
inherit IApplicationLifetime
override TryShutdown: ?exitCode: int -> bool
member Args: string array
member MainWindow: Window
member ShutdownMode: ShutdownMode
member Windows: IReadOnlyList<Window>
member ShutdownRequested: EventHandler<ShutdownRequestedEventArgs>
<summary> Controls application lifetime in classic desktop style </summary>
<summary> Controls application lifetime in classic desktop style </summary>
val desktop: ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime
property ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.MainWindow: Window with get, set
<summary> Gets or sets the main window of the application. </summary>
<value> The main window. </value>
<summary> Gets or sets the main window of the application. </summary>
<value> The main window. </value>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val app: int
type AppBuilder =
member AfterPlatformServicesSetup: callback: Action<AppBuilder> -> AppBuilder
member AfterSetup: callback: Action<AppBuilder> -> AppBuilder
member ConfigureFonts: action: Action<FontManager> -> AppBuilder
member SetupWithLifetime: lifetime: IApplicationLifetime -> AppBuilder
member SetupWithoutStarting: unit -> AppBuilder
member Start: main: AppMainDelegate * args: string array -> unit
member UseLifetimeOverride: func: Func<Type,IApplicationLifetime> -> AppBuilder
member UseRenderingSubsystem: initializer: Action * ?name: string -> AppBuilder
member UseRuntimePlatformSubsystem: initializer: Action * ?name: string -> AppBuilder
member UseStandardRuntimePlatformSubsystem: unit -> AppBuilder
...
<summary> Initializes platform-specific services for an <see cref="T:Avalonia.Application" />. </summary>
<summary> Initializes platform-specific services for an <see cref="T:Avalonia.Application" />. </summary>
AppBuilder.Configure<'TApp (requires default constructor and 'TApp :> Application)>() : AppBuilder
AppBuilder.Configure<'TApp (requires 'TApp :> Application)>(appFactory: System.Func<'TApp>) : AppBuilder
AppBuilder.Configure<'TApp (requires 'TApp :> Application)>(appFactory: System.Func<'TApp>) : AppBuilder